lundi 9 février 2015

how to use spfile with taxanomies



I am trying to add a file and column data to a list but get this error An exception of type 'Microsoft.SharePoint.SPException' occurred in Microsoft.SharePoint.dll but was not handled in user code



using (SPWeb web = mysites.RootWeb)
{
mysites.OpenWeb();

SPList list = web.Lists["MyList"];
string file = fileName;

Stream fStream = File.OpenRead(file);
var byteArray = new byte[fStream.Length];
string filename = System.IO.Path.GetFileName(file);
if (list != null)
{
string fileUrl = list.RootFolder.Url + "/" + filename;
SPFile fileSp = list.RootFolder.Files.Add(fileUrl, byteArray, true);
SPListItem item = fileSp.Item;
item["Name"] = fileSp;

foreach (var pair in termsDic)
{
var key = pair.Key;
var value = pair.Value;

TaxonomyField taxonomyField = web.Site.RootWeb.Fields["Type"] as TaxonomyField;
TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(taxonomyField);
taxonomyFieldValue.TermGuid = value;
taxonomyFieldValue.Label = valKey;
item["Type"] = taxonomyFieldValue;
}



}

}

item.Update();







0 commentaires:

Enregistrer un commentaire