Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用WebApi打开office文档,并使用MS office将其保存回站点_.net_Asp.net Mvc_Sharepoint_Ms Office_Asp.net Web Api - Fatal编程技术网

.net 使用WebApi打开office文档,并使用MS office将其保存回站点

.net 使用WebApi打开office文档,并使用MS office将其保存回站点,.net,asp.net-mvc,sharepoint,ms-office,asp.net-web-api,.net,Asp.net Mvc,Sharepoint,Ms Office,Asp.net Web Api,我做了一些研究,但这超出了我的理解。我正在使用Fiddler尝试捕获请求/响应。 我们的目标是,这个webapi的行为就像一个sharepont文档存储库,没有那么多的资源和许可证。 我在获取文件方面取得了一些进展: public HttpResponseMessage Get(int id) { byte[] content = null; using (FileStream fs = File.Open(@"d:\some.docx", FileMode.Open))

我做了一些研究,但这超出了我的理解。我正在使用Fiddler尝试捕获请求/响应。
我们的目标是,这个webapi的行为就像一个sharepont文档存储库,没有那么多的资源和许可证。
我在获取文件方面取得了一些进展:

public HttpResponseMessage Get(int id)
{
    byte[] content = null;
    using (FileStream fs = File.Open(@"d:\some.docx", FileMode.Open))
    {
        content = new byte[fs.Length];
        fs.Read(content, 0, (int)fs.Length);
    }
    HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
    response.Content = new ByteArrayContent(content);
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/msword");
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
    {
        FileName = "some.docx"
    };
    return response;
}
浏览器提供打开文件的功能,但是文件名为
5
,因此此部分仍然无法正常工作。
请求很容易获取,由浏览器启动,响应如下(没有内容):

我通过url访问该文件:
http://localhost:49590/api/WordApi/5

与此同时,我发现了以下文章:
我承认我并不完全理解它,但我认为我应该在我的应用程序中实现一个
WebDAV

我试图添加一些选项,希望Office提出的请求有所改变,例如:

public HttpResponseMessage Options()
{
  HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
  response.Headers.Add("MS-AUTHOR-VIA", new[] { "LOCK", "UNLOCK", "PROPPATCH" });
  return response;
}
但不幸的是,一切都没有改变。办事处的请求是:

OPTIONS http://localhost:49590/api/WordApi/ HTTP/1.1
X-IDCRL_ACCEPTED: t
User-Agent: Microsoft Office Protocol Discovery
Host: localhost:49590
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache
然后它又做了一个:

HEAD http://localhost:49590/api/WordApi/5 HTTP/1.1
X-IDCRL_ACCEPTED: t
User-Agent: Microsoft Office Existence Discovery
Host: localhost:49590
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache
有什么方法可以欺骗Office在保存文件时发送web API吗?
另一件有趣的事情是,当我调试时,在应用程序中,方法
Options()
Head(int-id,[FromBody]string-value)
被调用了两次,但根据Fiddler的说法,在上述两种情况下,请求只发送了一次

你知道如何使用webapi实现这种打开/保存机制吗

更新:

看来大家都没抓住重点。问题不是打开文档,而是使用Office在本地保存文档(不是在应用程序中上载页面)。
如果使用附件作为内容配置,浏览器将以不同的方式打开文件。它将文件保存到临时文件,并从该位置打开文档。在这种情况下,Office甚至不会尝试连接到我的webapi。
但是,如果我使用内联Office,则会从网站位置打开文档,并通过选项和HEAD请求检查我的webapi的功能。
浏览器将生成以下打开的对话框:
如果设置为附件:

如果设置为内联:

答案是痛苦的。解决方案是在自定义处理程序中实现WebDAV。

您知道如何使用mvc和option/head调用打开和保存文件了吗?我找到了一种从浏览器打开office文档的简单方法。你有没有想过如何使用word将数据保存回服务器?你有没有一个简单的例子来说明如何通过web api使用web dav规范实现get和save?
HEAD http://localhost:49590/api/WordApi/5 HTTP/1.1
X-IDCRL_ACCEPTED: t
User-Agent: Microsoft Office Existence Discovery
Host: localhost:49590
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache