1

I've spent about 3-4 days on investigating this via stack overflow and google search engine.

My dilemma is this: I am tasked with displaying a file from a url (not sure if i can simply open it or have to save it to a folder) within a windows form on Visual Studio 2015. The link in question is this but will not work due to this being only accessible via internal network or VPN connected: http://QualityWorkbench/ivscripts/qwbcgi.dll/docfetch?db=live&id=1090

What I've accomplished so far is that that I've built the windows form portion based on this link from a stack overflow article which leads to a blog link:

How to display PDF or Word's DOC/DOCX inside WinForms window?

What I've built very similarly would work for links that have a file name within the url but not the Quality Workbench link mentioned above. An example is this: http://www.e-iceblue.com/images/test.docx

I've researched everywhere and various stack overflow articles talk about checking content disposition via HttpWebResponse headers but when i debug through it, the only headers i saw were these (nothing about content-disposition):

Header Name:Content-Length, Value :411

Header Name:Content-Type, Value :text/html

Header Name:Set-Cookie, Value :IGS_SessionID=53114; path=/; expires=Fri, 03 Jun 2016 14:01:34 GMT,sessionid=2d794a41-43ce-4c6b-96cc-7a832ac39670; path=/; expires=Fri, 03 Jun 2016 14:01:34 GMT

Header Name:Server, Value :Microsoft-IIS/7.5

Header Name:X-Powered-By, Value :ASP.NET

I know what I've listed is pretty vague so I'll be happy to provide any coding details or whatever info anyone needs to decipher my dilemma: how to download a file from a url that only ends with an id using Visual Studio 2015 C#. Ideally opening the file without saving it and display it into a window form is my ideal but I am also content in saving the file into a users download folder.

Community
  • 1
  • 1
vegeto18
  • 45
  • 1
  • 6
  • Have you tried opening the url's through a proxy such as fiddler? This will help you understand what is going on exactly. You mention that the Content-Type is text/html. If you expect a .docx the content type should be `application/vnd.openxmlformats-officedocument.wordprocessingml.document` My guess is that you're not using the correct url. – Hintham Jun 03 '16 at 14:48
  • I have not. I don't know what a fiddler is although I'll look it up. As for the 1090 link. It does provide a file. On the work network (be it at the office or VPN) I am prompted on IE to open, save, or save as the file. Opening it opens up word and saving it prompts me to save it as a word docx file. This link is active on our training manager site. Currently our workers click it and are prompted to open it in word. I'm tasked to keep it contained with a window form. Unfortunately for me I have no access to change how those links are created or defined. I'm given with has already existed. – vegeto18 Jun 03 '16 at 15:49

2 Answers2

0

First of all, you need to make sure the URL you use really provides you a file; as Hintham suggested in his/hers comment, what you receiving is not a docx file.

Second, in your code you need to make a HTTP request to the URL to get the file. Good practice would be to catch transmission and/or HTTP errors. In the response there will be the file if no HTTP errors has occurred during requesting.

The easiest way to do this (in my opinion) would be to engage the WebClient.DownloadData. It will retrieve the file into a byte array so you could fed your WinForms app with it for display. Take a look on the MSDN documentation - it's pretty straight forward.

Bozhidar Stoyneff
  • 3,576
  • 1
  • 18
  • 28
  • @bozhidarstinev - I followed that MSDN documentation you recommended and used an example from that. it does answer on WHY the content type is html/text instead of application/vnd.openxmlformats-officedocument.wordprocessingml.document. Apparently the data returned is a simple html file that (i assume) then calls the link again to open, save, saveas the word file. – vegeto18 Jun 03 '16 at 16:13
  • @vegeto18 - Correct. The MSDN cannot answer this; nor any client-side technology. This is what I meant by "you need to make sure the URL you use really provides a file". Try to type your link in the address bar of a browser to see what happens... – Bozhidar Stoyneff Jun 03 '16 at 16:25
  • @bozhidarstinev - with work credentials via VPN (or when i'm at the office) on IE the window is blank but I am prompted on what I want to do with "docfetchraw.docx" be it Open, Save, or Save As from qualityworkbench. Disconnected from the VPN I am taken to an html site that says that the qualityworkbench page is under construction. does this mean it tunnels from there to the actual server that houses the document? – vegeto18 Jun 03 '16 at 16:52
  • Exactly! Most likely, when you connect to the mentioned VPN, a DNS on the VPN server side recognizes `qualityworkbench` and translates it to the correct IP address. From there everything is peachy. However, when you're not connected to the VPN your ISP's or some other DNS intercepts the request for `qualityworkbench` - a non-existent host name on the Internet - and offers to buy it through returning HTML page to you. Really annoying but it happens. I hit this multiple times too. Anyway, I'm glad you figured it out... – Bozhidar Stoyneff Jun 06 '16 at 13:54
0

@bozhidarstoinev - after taking a long break and coming back to it, i reviewed what you provided and then viewed the html source of the link on IE. It was like you said, the link was referencing an html site which contained the real URL download link. I didn't catch it the first time due to fatigue but the true url download link was similarly named to what i provided in my problem save 3 characters added on.

Thanks for setting me on the right path!

vegeto18
  • 45
  • 1
  • 6