将文件和一些字段项目上载到文档库 [英] upload file and some field items to document library

查看:58
本文介绍了将文件和一些字段项目上载到文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要将文档上传到sharepoint文档库中,我是这样的:

字符串strsite =共享站点";
使用(SPSite mySite =新的SPSite(strsite))
{
使用(SPWeb web = mySite.OpenWeb())
{
SPFolder文件夹= web.Folders ["QEHS手册"];
SPFileCollection filecol = folder.Files;
布尔值replaceExistingFiles = true;
字符串文件名= System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
byte []内容=新的byte [Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];
SPFile已添加文件= filecol.Add(文件名,内容,replaceExistingFiles);
SPItem newItem = addedFile.Item;
newItem ["No."] = txtno.Text;
newItem [文档描述"] = txtdocdescription.Text;
newItem [文档编号"] = txtdocno.Text;
newItem ["Custodian"] = txtcustodian.Text;
newItem [修订版号"] = txtrevno.Text;
newItem [问题编号"] = txtissueno.Text;
newItem.Update();
addedFile.Update();
}
}

文件被上传.但是当iam尝试从sharepoint网站上将其写入时,它显示错误.错误消息为""由于内容存在问题,无法打开Office Open xml文件xxx,"任何人都可以帮助我..

To upload a document to sharepoint document library i did like this :

string strsite = "sharepoint site";
using (SPSite mySite = new SPSite(strsite))
{
using (SPWeb web = mySite.OpenWeb())
{
SPFolder folder = web.Folders["QEHS Manual"];
SPFileCollection filecol = folder.Files;
Boolean replaceExistingFiles = true;
string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
byte[] contents = new byte[Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];
SPFile addedFile = filecol.Add(filename, contents, replaceExistingFiles);
SPItem newItem = addedFile.Item;
newItem["No."] = txtno.Text;
newItem["Document Description"] = txtdocdescription.Text;
newItem["Document No."] = txtdocno.Text;
newItem["Custodian"] = txtcustodian.Text;
newItem["Revision No."] = txtrevno.Text;
newItem["Issue No."] = txtissueno.Text;
newItem.Update();
addedFile.Update();
}
}

the file gets uploaded. but when iam trying to pen it from sharepoint site, it is showning error.the error message is """the office open xml file xxx cannot be opened because there are problems with content""" can anyone pls help me..

推荐答案


使用另一种重载方法 < b> myLibrary.Files.Add();</b>

将哈希表作为参数的地方.
在哈希表中提供所有元数据争论

HashTable table = new HashTable();
table ["field_name1"] =字段value1"
table ["field_name2"] =字段value2"

将此哈希表对象作为论据发送给
myLibrary.Files.Add()方法.

这可能有帮助....
use another overload method for
<b>myLibrary.Files.Add();</b>

where it will take hashtable as argument.
provide all metadata arguement in the hashtable

HashTable table = new HashTable() ;
table["field_name1"] = "field value1"
table["field_name2"] = "field value2"

send this hashtable object as arguement to the
myLibrary.Files.Add() method.

this might help....


这篇关于将文件和一些字段项目上载到文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆