使用元数据将文件上传到 SharePoint 文档库
我正在使用以下代码将文件上传到 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*/ );
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*/ );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到你在哪里添加元数据,我看到你填充了一个哈希表,但没有对其进行任何操作
I don't see where you add the metadata, i see you filling a hashtable and do nothing with it