0

So, I'm actually trying to setup a Wopi Host for a Web project.

I've been working with this sample (the one from Shawn Cicoria, if anyone knows this), and he provides a whole code sample which tells you how to build the links to use your Office Web App servers with some files.

My problem here, is that his sample is working with files that are ON the OWA server, and i need it to work with online files (like http://myserv/res/test.docx. So when he reads his file content, he's using this :

var stream = new FileStream(myFile, FileMode.Open, FileAccess.Read);
responseMessage.Content = new StreamContent(stream);

But that ain't working on "http" files, so i changed it with this :

byte[] tmp;
using (WebClient client = new WebClient())
{
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    tmp = client.DownloadData(name);
}
responseMessage.Content = new ByteArrayContent(tmp);

which IS compiling. And with this sample, i managed to open excel files in my office web app, but words and powerpoint files aren't opened. So, here's my question.

Is there a difference between theses two methods, which could alter the content of the files that i'm reading, despite the fact that the WebClient alows "online reading" ?

Sorry for the unclear post, it's not that easy to explain such a problem x) I did my best.

Thanks four your help !

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Guillaume Munsch
  • 1,233
  • 17
  • 37
  • There's no such thing as an "http file" - what you've got there is a URL, no a file. Not sure what you mean by "which could alter the content of the files that I'm reading". If you need to be able to modify the file and then save it back, then the web server needs to support that (and you have to have permission...) – Jon Skeet Jun 17 '15 at 07:21
  • Nope, i just need to read it. (Sorry for the explanations :/). In fact, my office web app server need the content of the file that's going to be displayed. And the `FileStream` can only manipulate "local" files as in the answer below. For the permissions i checked them. What i did, is that i called the api link of my project which returns the content of the file passed in parameter. So i managed to download it like this. Then, i tried to open both of the ppt and docx files in the associates softwares. The word IS opening well ! But sadly not the powerpoint – Guillaume Munsch Jun 17 '15 at 07:30
  • I don't know if that's clear, it's really tough to explain all of this :/ – Guillaume Munsch Jun 17 '15 at 07:32
  • It's still not very clear, no... is your problem really "I've downloaded a Powerpoint file with WebClient, and it's not opening"? If so, the rest seems irrelevant... – Jon Skeet Jun 17 '15 at 07:34
  • No, that's not the problem. I'm not supposed to call this url, it's just for the test. The `office web app` is calling my application 2 times to be able to render a view of the document. First it asks some informations about it (size, ...). My app respond, and then the `office web app` asks my app to get the binary content of the file. And the sample that i post right up there is supposed to get the file content (With `WebClient`), and return it to the `office web app` so he can render a view. And this sample is working when i try it on excel files. – Guillaume Munsch Jun 17 '15 at 07:39
  • Okay, well I'm still very confused. I strongly recommend that you rewrite your question to try to clarify it - I may well still not be able to answer it, but it would increase the chances of someone else being able to. – Jon Skeet Jun 17 '15 at 07:56
  • I'll try to do it a bit later today ! Need to think about how I could clarify this ... – Guillaume Munsch Jun 17 '15 at 07:59

1 Answers1

1

Is there a difference between theses two methods, which could alter the content of the files that i'm reading, despite the fact that the WebClient allows "online reading"

FileStream open a file handle to a file placed locally on disk, or a remote disk sitting elsewhere inside a network. When you open a FileStream, you're directly manipulating that particular file.

On the other hand, WebClient is a wrapper around the HTTP protocol. It's responsibility is to construct HTTP request and response messages, allowing you to conveniently work with them. It has no direct knowledge of a resources such as a file, or particularly where it's located. All it knows is to construct message complying with the specification, sends a request and expects a response.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321