目前,我们的应用程序正在使用Word文档,该文档存储在本地文件系统中。它读取并操作它,将更新的文档返回给用户。我有以下代码:
var tempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".docx");
File.Copy(fileName, tempFileName);
if (!File.Exists(tempFileName))
throw new ArgumentException("Unable to create file: " + tempFileName);
using (var doc = WordprocessingDocument.Open(tempFileName, true))
它正在创建临时文件并复制单词doc然后操作临时文件。这样原来的单词doc就不会受到影响。
我们最近被要求将单词doc移动到sharepoint,我可以使用WebClient类连接并验证文件是否存在,但我无法弄清楚如何从Sharepoint复制文件。我试过了:
var client = new WebClient { Credentials = CredentialCache.DefaultCredentials };
// Create a request for the URL.
WebRequest request = WebRequest.Create(fileName);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
var response = (HttpWebResponse)request.GetResponse();
//check response status
if (String.Compare(response.StatusDescription, "OK", StringComparison.OrdinalIgnoreCase) == 0)
{
client.DownloadFile(fileName, Guid.NewGuid() + ".docx");
//URL exists so that means file exists
return true;
}
throw new ArgumentException("File \"" + fileName + "\" do not exists");
问题是当我调用DownloadFile时它可以工作,但我不知道该文件的发送位置。有没有办法连接到sharepoint中的文件,只是将其作为原始方式复制到用户tempath?