FileStream or WebClient
I am currently creating a preview with technologies Wopi
and Office Web App
from Microsoft and I am having a problem. Sorry for my bad english, but I will try to express myself as best I can.
So! I am generating a preview by loading the content of the file and saving it to HttpContent
. First, I tried it on the files that were in ~/App_Data/
my project. I have read its contents with the class FileStream
and convert it to HttpContent
using it: StreamContent(myFileStream)
. So THIS works great!
BUT, I need my project to work with files that are stored on servers that are only accessible from the internet (so the physical URLs should look like this: http://myServer/res/file.pdf
for example). I couldn't use the class FileStream
here, so I did it like this:
byte[] tmp;
using (WebClient client = new WebClient())
{
client.Credentials = CredentialCache.DefaultNetworkCredentials;
tmp = client.DownloadData("http://myServer/res/file.pdf");
}
myHttpContent = new ByteArrayContent(tmp);
The thing is, this small sample seems to work, but no preview is generated after that and this is the only piece of code that I have changed. I checked some post stuff here, so: I have access to the file and I can read it.
So my question is if this is a good way to get the contents of the files, is it outdated, what should I do to try and fix it?
Hope my post is clear enough and thanks for reading!
source to share
I think you can do the following
MemoryStream ms;
using (WebClient client = new WebClient())
{
client.Credentials = CredentialCache.DefaultNetworkCredentials;
ms = new MemoryStream(client.DownloadData("http://myServer/res/file.pdf"));
}
Then use a memory stream that should behave the same way with your file stream.
source to share