0

嗨,我正在尝试使用带有元数据的客户端 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。非常感谢任何帮助。

4

1 回答 1

0

在 executeQuery(); 之前需要一个凭证;和 SaveBinaryDirect();

例如:

mClientContext.Credentials = new NetworkCredential("LoginID","LoginPW", "LoginDomain");

SPFile newFile = mRootWeb.GetFileByServerRelativeUrl(targetLocation);
mClientContext.Load(newFile);
mClientContext.ExecuteQuery();
于 2014-06-27T08:53:02.747 回答