Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public string GetCheckListDocUrl(object DeliverablesID)
{

SOBO objScope = new SOBO();
objScope.DelivarablesID = Convert.ToInt32(DeliverablesID);
DataSet dsDelivarablesDoc = objScope.GetSODeliverablesDocument();
// scopeDoc = dsDelivarablesDoc.Tables[0].Rows[0]["PLC_Filepath"].ToString();
string siteurl = System.Configuration.ConfigurationManager.AppSettings["websiteroot"].ToString();
string path = DeliverablesID.ToString().Replace("~", "").TrimStart('/');
siteurl = siteurl + path;
return siteurl;
}

What I have tried:

i'm trying to open a file by clicking on filename on browser(Google Chrome) but when i'm clicking on file despite of having right address browser does not open the file
Posted
Updated 28-Jun-23 2:48am
Comments
[no name] 27-Jun-16 7:28am    
What kind of file is that ? As long as I know, it is a security problem, if you can open file from browser click. Browser can only automatically open HTM, HTML, TXT, Images.... and not EXE, ZIP, ...
Member 10549697 27-Jun-16 7:29am    
even it does not open text files

Try the given below code -

C#
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;

response.AddHeader("Content-Disposition", "attachment;filename=\"" + System.IO.Path.GetFileName(HttpContext.Current.Server.MapPath(FileName)) + "\"");
byte[] data = req.DownloadData(HttpContext.Current.Server.MapPath(FileName));
response.BinaryWrite(data);
response.End();
 
Share this answer
 
Comments
Member 10549697 27-Jun-16 7:57am    
how to add filename in this code?
Madhu Nair 27-Jun-16 8:48am    
Create a function with the code and use FileName variable mentioned in the code as a parameter where in you can pass the full path of the file name. In the code i posted I was passing the file name as "~/upload/test.txt". Hence I used Server.MapPath function.
Member 10549697 29-Jun-16 3:02am    
okay.thank you.it helped
How to open file in browser with hyperlink?
 
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