2016-03-17 57 views
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(); 
     } 
    } 
} 

回答

0

我在file.Update();行之前添加了file.ListItemAllFields.Update();代码行,现在该字段也被更新了。

相关问题