开发者

Uploading files to a SharePoint document library with 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜