使用元数据将文件上载到SharePoint文档库

时间:2010-11-11 00:54:16

标签: sharepoint metadata document

我使用以下代码将文件上传到SharePoint文档库,但它没有附加元数据:

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();
}

我正在使用此函数调用:

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

1 个答案:

答案 0 :(得分:1)

我没有看到你添加元数据的位置,我看到你填写哈希表并且不做任何事情