簡體   English   中英

在Asp.net上下載文件

[英]Downloading FIles on Asp.net

這是我的代碼

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";
    }
}

我可以上載文件,但在我的visual studio 2013中看不到它。我需要查看上載的文件才能下載並將其文件路徑保存到Sql數據庫。

這是我的代碼下載文件

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();
    }

發布Web應用程序時遇到一個問題。在將應用程序發布到Files系統后,此Files夾無法復制到Visual Studio 2010的Published文件夾上。所以我在發布Web應用程序后手動復制包含內容的Files目錄並粘貼該目錄。 現在好啦

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM