[英]Downloading FIles on Asp.net
this is my code 这是我的代码
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/CustomerFiles/") + filename);
lblResult.Text = "Your File " + filename + " is Succesfull uploaded!";
//lblFile.Text = FileUpload1.FileName;
lblFile.Text = "../CustomerFiles/" + filename;
Page_Load(sender, e);
}
catch (Exception)
{
lblResult.Text = "Upload Failed";
}
}
I can Upload files but I can't see it in my visual studio 2013.I need to see my uploaded files in order for me to download it and save its filepath to Sql Database. 我可以上载文件,但在我的visual studio 2013中看不到它。我需要查看上载的文件才能下载并将其文件路径保存到Sql数据库。
This my code to download the file 这是我的代码下载文件
protected void Button1_Click(object sender, EventArgs e)
{
string filename = "~/Files/Mastering MeteorJS Application Development.pdf";
String _fileName = "akash";
string path = MapPath(filename);
//byte[] bts = System.IO.File.ReadAllBytes(path);
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition:", "attachment;filename=" + _fileName + ".pdf");
Response.TransmitFile(path);
//Response.Close();
}
There is a problem i faced when published the web application.This Files
folder does not copy on Published folder on visual studio 2010 after publishing the app to file system.so i manually copy the Files
directory with contents after published of web application and paste in that dir. 发布Web应用程序时遇到一个问题。在将应用程序发布到Files
系统后,此Files
夹无法复制到Visual Studio 2010的Published文件夹上。所以我在发布Web应用程序后手动复制包含内容的Files
目录并粘贴该目录。 now its ok 现在好啦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.