问题描述
要将文档上传到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..
推荐答案
这篇关于将文件和一些字段项目上载到文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!