使用客户端对象模型上传带有元数据的文件并签入到sharpoint文件夹



嗨,我正在尝试使用带有元数据的客户端api将文件上传到sharepoint 2010,并在完成后签入该文件。以下是我的代码:

public void UploadDocument(SharePointFolder文件夹,字符串文件名,布尔覆盖){

var fileInfo = new FileInfo(filename);
var targetLocation = String.Format("{0}{1}{2}", folder.ServerRelativeUrl,
    Path.AltDirectorySeparatorChar, fileInfo.Name);
using (var fs = new FileStream(filename, FileMode.Open))
{
    SPFile.SaveBinaryDirect(mClientContext, targetLocation, fs, overwrite);
}
// doesn't work
SPFile newFile = mRootWeb.GetFileByServerRelativeUrl(targetLocation);
mClientContext.Load(newFile);
mClientContext.ExecuteQuery();
//check out to make sure not to create multiple versions
newFile.CheckOut();
// use OverwriteCheckIn type to make sure not to create multiple versions 
newFile.CheckIn("test", CheckinType.OverwriteCheckIn);
mClientContext.Load(newFile);
mClientContext.ExecuteQuery();
//SPFile uploadFile = mRootWeb.GetFileByServerRelativeUrl(targetLocation);
//uploadFile.CheckOut();
//uploadFile.CheckIn("SOME VERSION COMMENT I'D LIKE TO ADD", CheckinType.OverwriteCheckIn);
//mClientContext.ExecuteQuery();

}

我可以上传文件,但我不能添加任何元数据,文件已签出。我想添加一些元数据,并在完成后签入该文件。

我的SharePointFolder类有要上传到的文件夹路径的serverRelativeUrl。非常感谢您的帮助。

在执行Query()之前需要一个凭据;和SaveBinaryDirect();

例如:

mClientContext.Credentials = new NetworkCredential("LoginID","LoginPW", "LoginDomain");
SPFile newFile = mRootWeb.GetFileByServerRelativeUrl(targetLocation);
mClientContext.Load(newFile);
mClientContext.ExecuteQuery();

相关内容

  • 没有找到相关文章

最新更新