如何在浏览器中打开超链接文件 [英] How to open file in browser with hyperlink
问题描述
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();
字符串路径= DeliverablesID.ToString()。Replace(〜,)。TrimStart('/');
siteurl = siteurl + path;
return siteurl; < br $>
}
我尝试过:
我试图通过点击浏览器(谷歌浏览器)上的文件名来打开文件,但是当我点击文件时尽管有正确的广告连衣裙浏览器无法打开文件
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
推荐答案
尝试下面给出的代码 -
Try the given below code -
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();
这篇关于如何在浏览器中打开超链接文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!