0
SharePoint 2013SharePoint:爲什麼我的領域的價值沒有改變?
爲什麼我的字段值沒有更改?
using Microsoft.SharePoint;
using System;
using System.IO;
namespace SharePoint2013_sandbox {
internal static class Example {
// I have some site for learning
const String sitePath = "http://sharepoint2013/sites/sandbox2";
// The Id of the field that is used by uploaded files
static readonly Guid fieldId = new Guid(
"{126801d9-c5c7-48a5-ab82-5ef48a76f934}");
internal static void WorkWithFields() {
if (!SPSite.Exists(new Uri(sitePath))) {
Console.WriteLine("The {0} site not found.", sitePath);
}
else {
using (SPSite siteCollection = new SPSite(sitePath)) {
using (SPWeb site = siteCollection.OpenWeb()) {
SPFieldChoice fldProjCode = site.Fields[fieldId]
as SPFieldChoice;
SPList list = site.Lists["Some document collection"];
using (FileStream fs = new FileStream(
@"C:\Public\Data\Drawing1.dwg",
FileMode.Open, FileAccess.Read, FileShare.Read)) {
SPFile file = list.RootFolder.Files.Add(
"Drawing1.dwg", fs, true);
// Now I set the value for the field of the file...
String fldValue = fldProjCode.Choices[1];
file.Item[fldProjCode.Id] = fldValue;
file.Update();
}
site.Update(); // But field value of my file wasn't updated.
}
}
}
Console.WriteLine("Press any key for exit...");
Console.ReadKey();
}
}
}