Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

im trying to make a program that would open a file (.pdf) from a server (xxx.xxx.xxx.xxx/location/docs/file.pdf) i dont have any code right now, i can open a file (.pdf) that is in my computer. but i dont know how to do it, any help??

thanks
Posted
Comments
Jibesh 12-Dec-12 16:28pm    
the server you mean here is a network computer ? if yes you can use FileStream classes to open files.
Akbar Ali Hussain 12-Dec-12 16:30pm    
You can use the same code which you open from local for opening from server also. Only difference will be the path. If the logged in user has access to the server path, then the application can open file. If the logged in user doesnt have access, you have to add extra code for authentication.

azteca_04143,

When you try to open a file from a server, just use the UNC path. That basically means putting slashes in front of the resource. From your example:

\\xxx.xxx.xxx.xxx\location\docs\file.pdf

If your account has access to that location, it'll just work. You can test this theory by placing the path above in Windows Explorer directly. If it opens up, you'll be fine.

If it doesn't open up, you have a few options:
* Map a network drive and use a drive letter. You can specify alternate credentials when doing this.
* FTP the File

Good luck!

Hogan
 
Share this answer
 
Comments
azteca_04 12-Dec-12 16:33pm    
The File is in another location, other city and i upload the file via C# to FTP, so, how would i go from doing the credentials to open the file??

thanks for the quick replies
Jibesh 12-Dec-12 16:41pm    
If you have the credentials to connect to the ftp then you will also have the credential to open the file.
azteca_04 12-Dec-12 16:45pm    
any code as to how would this be done?? i do have the credential and directory i just need how would de conextion and how would the .pdf would be open from the server?
snorkie 12-Dec-12 18:04pm    
Use the System.Process.Start() method. I've provided the MSDN link below with an example. As long as the machine has a mime type set up (you can double click and it opens), Windows will figure out what application is used and open it up. So place the full UNC path (if you can) or local path of the file and it'll open with your PDF viewer.

System.Diagnostics.Process openPDF = new System.Diagnostics.Process();
openPDF.StartInfo.FileName = "Your File Path.pdf";
openPDF.StartInfo.UseShellExecute = false;
openPDF.StartInfo.RedirectStandardInput = false;
openPDF.StartInfo.RedirectStandardOutput = false;
openPDF.Start();

http://msdn.microsoft.com/en-us/library/e8zac0ca.aspx
snorkie 12-Dec-12 16:44pm    
It depends on your environment. I often deal with files in other cities/country as if they were sitting next to me because the network was set up for files/server to be local.
 
Share this answer
 
Comments
azteca_04 12-Dec-12 17:05pm    
Thks, this works for now, i would look to see if instead of actualy downloading the file i can open it and view it instead,

thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900