我想提示一个保存对话框到user.The文件taype是.wav。此操作如下所示
public ActionResult MergeSelectedRecords(string mergeFileName, List<String> selectedRecords)
{
string urlFilePath=GetFilePath(); //get virtual path of file.
ControllerContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + "cccc");
string filePath = ControllerContext.HttpContext.Server.MapPath(urlFilePath);
return File(filePath, ".wav");
}一个sampl文件路径是'http:/localhost:2694/DATA/MERGE/OUT/1/cccc‘。
但它显示了如下所示的错误
'http:/localhost:2694/DATA/MERGE/OUT/1/cccc' is not a valid virtual path. 这是一种将保存文件对话框提示给用户的正确方法吗?
编辑
有时,用户没有可用的文件。因此,如果urlFilePath="“,我只想显示一个警告。
如果没有文件路径可用,我如何返回一个空的resul.And,向user..The发出警报,下面是我想要的东西
public ActionResult MergeSelectedRecords(string mergeFileName, List<String> selectedRecords)
{
string urlFilePath=GetFilePath(); //get virtual path of file.
if(urlFilePath!="")
{
ControllerContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + "cccc");
string filePath = ControllerContext.HttpContext.Server.MapPath(urlFilePath);
return File(filePath, ".wav");
}
else
{
//what i return here? If it possible i only want to display an alert .But the page user viewing cannot refreshed
}
}发布于 2011-03-29 06:13:10
要传递给MapPath方法的MapPath参数必须是以~/开头的同一站点中的相对url。示例:
public ActionResult MergeSelectedRecords(string mergeFileName, List<String> selectedRecords)
{
string urlFilePath = "~/Files/ccc.wav";
string filePath = Server.MapPath(urlFilePath);
return File(filePath, ".wav", "ccc");
}如果网址不是您网站的一部分,您需要先下载该文件。示例:
public ActionResult MergeSelectedRecords(string mergeFileName, List<String> selectedRecords)
{
using (var client = new WebClient())
{
byte[] file = client.DownloadData("http://foo.com/ccc.wav");
return File(file, ".wav", "ccc");
}
}https://stackoverflow.com/questions/5468518
复制相似问题