【发布时间】:2011-04-04 23:35:48
【问题描述】:
我想问一下,当单击特定链接按钮或超链接时,如何使用其应用程序打开特定文件(该文件在服务器之外,我有一个存储在配置文件中的相对路径)。 .
喜欢:
开场
.docx with word.
或
.pdf 与 acrobat 阅读器
我尝试了几种方法,但是,我得到了不同的错误,例如
不能使用前导 .. 退出顶级目录
我的 .cs:
public void ProcessRequest(HttpContext context)
{
int newsId = int.Parse(context.Session["newsId"].ToString());
int FK_UnitId = int.Parse(context.Session["UserData"].ToString());
string dirPathForTextFiles = ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
DataTable UpdatedDateTable = (DataTable)context.Session["theLastUpdatedTextFile"];
UpdatedDateTable.AcceptChanges();
context.Session.Add("currentTextFile", UpdatedDateTable);
List<string> l = new List<string>(UpdatedDateTable.Rows.Count);
try
{
l.Add(dirPathForTextFiles + UpdatedDateTable.Rows[0]["fileName"].ToString());
context.Response.ContentType = getContentType(dirPathForTextFiles + UpdatedDateTable.Rows[0]["fileName"].ToString());
System.Diagnostics.Process.Start(l[0]);
context.ClearError();
}
catch (IOException e)
{
string message = e.Message;
}
}
string getContentType(String path)
{
switch (Path.GetExtension(path))
{
case ".doc": return " application/msword";
case ".docx": return "application/msword";
case ".pdf": return "application/pdf";
default: break;
}
return "";
}
【问题讨论】:
-
你在问什么?你能举个例子吗?