Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to open a file in my browser, it shows access is denied error

I tried System.Diagnostics.Process.Start(strFilePath & strFileName) , this works on local but not on server and tried the following code


XML
strTemp = "<script language='javascript'>function NewWindow()
  {window.open("file://C:\\Users\\Ruban Jayakumar\\Desktop\\New folder\\boot strap icons.txt",'testpage','directories=no,location=no,status=no,toolbar=no,menubar=yes,height=450,width=700,left=10,top=10,Resizable=yes');return false; }</script>"
ClientScript.RegisterClientScriptBlock(Me.GetType, "SecurityPolicy", strTemp)



but error occurs, is there any other option ??
Posted
Comments
John C Rayan 2-Jun-15 8:36am    
This is wrong.
window.open("file://C:\\Users\\Ruban Jayakumar\\Desktop\\New folder\\boot strap icons.txt"

It has to refer your server like http:\\yourdomain\filepath
[no name] 2-Jun-15 8:41am    
Nope, I have to open an external file, i e from my client ,machine...
John C Rayan 2-Jun-15 9:03am    
you cannot. you have to look at internet security settings. For security reasons the browsers don't allow it. You have to change the settings.

1 solution

And it is actually good news for you!!!
What you saw here is security in action...
Imagine that anyone, who whish so can write a web site that can access your C: drive without any restriction...
So, by definition web pages have no access to the local drives on the computer on which the browser runs...
...
But I suspect that you meant to open a file from the C: drive of the server from where you served the web page...and it should be a real security disaster if a could access the drives on the web server from within a web page just because it was served from that server originally...
If you want to share a file from your server you have several secure options:
1. Create a download button that does it for you
2. Share the file using Virtual Directory
3. Create a page to stream the files directly to client...(Stream Your Documents Using Simple Web Page[^])
 
Share this answer
 

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