开发者

Uploading files to a SharePoint document library with metadata

开发者 https://www.devze.com 2023-01-24 17:30 出处:网络
I am using the following code to upload a file to a SharePoint Document Library but it\'s not attaching the metadata:

I am using the following code to upload a file to a SharePoint Document Library but it's not attaching the metadata:

private void UploadFileToSharePoint(开发者_开发知识库string strInputFileName, string sDocLibraryName)
{
    SPWeb site = SPContext.Current.Web;
    SPList myList = site.Lists[sDocLibraryName];
    string destFileUrl = myList.RootFolder.ServerRelativeUrl + @"/New.txt";
    site.AllowUnsafeUpdates = true;
    // FileStream fileStream = File.Open(strInputFileName, FileMode.Open);
    byte[] strm = File.ReadAllBytes(strInputFileName);
    // newFile.CheckIn("File added");
    //SPListItem item = newFile.Item;
    //item.File.CheckOut();
    Hashtable ht = new Hashtable();
    ht.Add("Status Indicator", "hello");
    ht.Add("Status Description", Description.Text);
    ht.Add("Status", "Delayed");
    //item.Update();
    //item.File.CheckIn("File with metadata");

    myList.RootFolder.Files.Add(destFileUrl,strm,ht, true/*overwrite*/);
    myList.Update();
}

I am using this function call:

UploadFileToSharePoint(@"C:\check.txt", 
                        "Project Status" /* name of Dc Library*/ );   


I don't see where you add the metadata, i see you filling a hashtable and do nothing with it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号