首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

C#向sharepointlibrary上传文件,并更新该记录的其它属性,该如何解决

2012-03-22 
C#向sharepointlibrary上传文件,并更新该记录的其它属性首先:必须使用xxx.asmx 服务才行,因为web服务器上

C#向sharepointlibrary上传文件,并更新该记录的其它属性
首先:必须使用xxx.asmx 服务才行,因为web服务器上不一定会安装sharepoint(sharepoint服务器和web服务器可能是分离的)
假定library名称为LabDemo
有如下属性
DemoName, DemoRemark,DemoFile(用于存放文件的列的名称)

能一次性上传文件并且给其它列赋值最好。
我目前的想法是:
1)先上传文件(文件名有规则,肯定唯一不用考虑重名覆盖的情况),该步骤已经实现。
2)根据文件名获取该记录的ID
3)使用caml update library where ID = ID.
后两步不知道怎么搞了,按照msdn上的demo没成功。如果您知道,麻烦把代码写的完整一些(别来个意识流,本人水平洼,请谅解)

[解决办法]
不好意思,没看到后面的括号。。。
//Upload document into this folder.
// List of desination Urls.
string[] destinationUrls = { fileUrl };

// Empty Field Information.
IMS.IMSCopy.FieldInformation information = new
IMS.IMSCopy.FieldInformation { DisplayName = fielddisplayname, 
InternalName = fieldinternalname,
Type = IMS.IMSCopy.FieldType.Text,
Value = thevalueyouwanttoset };

IMS.IMSCopy.FieldInformation[] info = { information };

// To receive the result Xml.
IMS.IMSCopy.CopyResult[] result;

copy.CopyIntoItems(fileUrl, destinationUrls, info, documentByteArray, out result);

不知道你上传文件用的是不是Copy.asmx。。。
[解决办法]
简单实用的 方法 就是自己在moss server上做一个 webservices 
然后添加一个自己写上传的方法
 [WebMethod]
public bool UploadFileToDocument(string p_siteURL,string p_webURL,string p_docTitle, string p_folder,string p_fileName, byte[] p_fileByte)
{
bool flag = false;
SPSecurity.RunWithElevatedPrivileges(delegate()
{

using (SPSite oSite = new SPSite(p_siteURL))
{
using (SPWeb oWeb = oSite.OpenWeb(p_webURL))
{
SPList oList = oWeb.Lists[p_docTitle];
SPFile file = oWeb.Files.Add(oWeb.Url.ToString() + "/" + oList.Title.ToString() + "/" + p_fileName, p_fileByte);
file.Update();
SPListItem oItem = file.Item;
oItem["DemoName"] = "demoname";
oItem["DemoRemark"] = "";
oItem.SystemUpdate(true);
flag = true;
}

}
});
return flag;
}
试一下吧

热点排行