I'm trying to open a document on server through google docs.
I can get the path and name of the file on the server.
And then on Button click event I wrote a method to open the file through google document reader.
string path = \\xxx-yyyyy-zzz\DocShare\sample1.doc //path of the file on server
Response.Redirect("http://docs.google.com/viewer?url=" + path);
When I run this code, I'm getting something like below
Can some one help me to find where did I go wrong? Is there any other method to open any document(ppt, doc, pdf etc) using google document reader.
TIA
What is \\xxx-yyyyy-zzz\DocShare\sample1.doc and where it is ?
A relative url dosen't specify a protocol & domain which makes the
browser to assume the document is referd from the same site/domain.
Please verify if you can access the document itself with the relative path.
http://docs.google.com/viewer?url=https://s3.amazonaws.com/scotchio/First-Node-App.pdf works for me as i can access the pdf. Try using the absolute url of the document
It doesn't work most likely because the file is not accessible from the Internet. The google doc previewer needs to be able to access the file in order to display it.
Related
I have a docx file which I would like to modify according to web user input. So, after the user submits the form on the web page, I need to modify the original docx file, and then download it to the user.
I try to store the original file as a resource file in my project, but I can't open it programatically.
That's what I tried in the post controller:
using Microsoft.Office.Interop.Word;
...
Application app = new Application();
Document document = app.Documents.Open(Properties.Resources.___, ReadOnly: false);
But I received a System.Runtime.InteropServices.COMException (0x80020005 (DISP_E_TYPEMISMATCH))
I also don't know how to download the modified file. In a simple console application document.SaveAs2(newPath); worked, but it doesn't seem to work for downloading.
(I'm not even sure that this whole way could work. If I can't use Microsoft.Office.Interop.Word this way, please let me know.)
If you want to manipulate docx files it's best to use the OpenXML API rather than the InterOP. See https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk?redirectedfrom=MSDN
I have a requirement of reading the content of PDF file from browser using c# and then save it locally. There is no physical existence to that file. It is served when file code is provided using the query string. The sample url is like http://something/ReportStatus.aspx?indvl_pk=12334. I am getting no way to do that. Any help is appreciated. Thanks is advance.
Requirement:
I have a pdf file in my machine. Using console\windows application, i need to open that pdf file from browser itself. I am getting answers to open pdf file in browser using ASP.NET. But i need answer to open pdf in browser using console app.
I tried the below code:
string localURL = #"C:\MyLocation\apllication demo.pdf";
System.Windows.Controls.WebBrowser webbrowser = new System.Windows.Controls.WebBrowser();
webbrowser.Navigate(localURL);
But no use. It asusual opening in its default application.
This is simply because you are supplying a wrong path.
For browser, the path would look like this:
string localURL = "file:///C:/MyLocation/apllication%20demo.pdf"
Note that %20 is a space character,so perhaps use string.Replace(" ","%20") when building the Url.
I'm trying to download files directly from a list of urls.
I was able to download most files successfully except for the .docx. I was able to download the .docx file, but when I try to open it, the error message shows that "The file is corrupt and cannot be opened", when I try to repair it with Microsoft Word, I got another error message saying "Microsoft Office cannot open this file because some parts are missing or invalid". I don't have any issue when download pdf files.
My code is very simple and it looks like this:
WebClient webClient = new WebClient();
webClient.DownloadFile("http://somehost/somefile.docx", "C:\\somefolder\\somefile.docx");
webClient.Dispose(); //I added this line just to see if it will fix the problem but no it didn't
I went to the urls in the browser and make sure that the files does exist and are not corrupted. The urls are just fine and I was able to download files directly from the urls in a browser and the file opens.
Additional Information:
I did find one thing that's different for pdf url and docx url, but I really don't think it has anything to do with my problem. When I go to the pdf url in a browser, the pdf was displayed in the browser. However, when I go to the docx url, the page doesn't show anything, but the download for the file automatically starts. I don't think this will make a difference but just FYI.
EDIT 10:38AM
I just tried the Async method. I was able to download the docx file and open it, but it appear as a blank word document, which is still not correct. The same docx file I download from the browser does have content.
webClient.DownloadFileAsync(new Uri("http://somehost/somefile.docx"),"C:\\somefolder\\somefile.docx");
DownloadFileAsync downloads file in background, and your application probably terminates before download is completed.
You should wait for DownloadFileCompleted event, or use a DownloadFile method that will wait until file will be downloaded.
Thank you everyone for trying to help, I really appreciate it.
I realize that the problem was actually me not concatenating the url correctly. Right, a stupid mistake I made...
WebClient didn't throw error for incorrect format (for whatever reason), and my log file was not logging the actual url that I was trying to connect to, so I didn't realize it was doing the wrong thing.
Anyway, thank you all for the help and the comments that help me figure out what the problem was.
I've seen various solutions to saving a file using WatiN.
My current issue is similar to the others described, I need to save a PDF file, but there's a registry key that tells IE to automatically open the PDF in a new window, rather than save it.
Ideally, I could just delete that registry key and move on. However, our security policy forbids me to do that (ugh.)
I'm looking for a way to find a link, right-click, and save-as using a built-in WatiN mechanism, rather than using mouse_event in user32.dll.
Is this possible?
Thanks for the help!
This is a very old question but just as a reference for other I'll post a solution to it.
I think that the approach that you are thinking of is incorrect. If you do have a link to a PDF you do have the address of the PDF (even if you have to go through other pages to form the final download URL, which you can emulate with Watin anyway) if you do have the address of the PDF file then you should just download it:
At this point you should get the link href string (that should contain the file you want to download)
using (WebClient client = new WebClient())
{
string DownloadFolder = #"C:\DownloadFolder";
if (Directory.Exists(DownloadFolder))
{
string downloadURL = "https://www.somesite.com/somepath/filename.pdf"; // this should come from the href on the a link.
client.DownloadFile(downloadURL, DownloadFolder + "\\somefilenam.pdf");
}
}