Datei vom server herunterladen asp.net

Ich möchte zum download einer Datei von einem server auf einem lokalen host.

ich habe einen code aus dem Netz, die sollte funktionieren, aber funktioniert nicht

     protected void Button4_Click(object sender, EventArgs e)
    {
     //To Get the physical Path of the file(test.txt)
    string filepath = Server.MapPath("test.txt");

    //Create New instance of FileInfo class to get the properties of the file being downloaded
   FileInfo myfile = new FileInfo(filepath);

   //Checking if file exists
   if (myfile.Exists)
   {
   //Clear the content of the response
   Response.ClearContent();

//Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);

//Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());

//Set the ContentType
Response.ContentType = ReturnExtension(myfile.Extension.ToLower());

//Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);

//End the response
Response.End();
  }

    }

    private string ReturnExtension(string fileExtension)
    {
        switch (fileExtension)
        {
            case ".htm":
            case ".html":
            case ".log":
                return "text/HTML";
            case ".txt":
                return "text/plain";
            case ".doc":
                return "application/ms-word";
            case ".tiff":
            case ".tif":
                return "image/tiff";
            case ".asf":
                return "video/x-ms-asf";
            case ".avi":
                return "video/avi";
            case ".zip":
                return "application/zip";
            case ".xls":
            case ".csv":
                return "application/vnd.ms-excel";
            case ".gif":
                return "image/gif";
            case ".jpg":
            case "jpeg":
                return "image/jpeg";
            case ".bmp":
                return "image/bmp";
            case ".wav":
                return "audio/wav";
            case ".mp3":
                return "audio/mpeg3";
            case ".mpg":
            case "mpeg":
                return "video/mpeg";
            case ".rtf":
                return "application/rtf";
            case ".asp":
                return "text/asp";
            case ".pdf":
                return "application/pdf";
            case ".fdf":
                return "application/vnd.fdf";
            case ".ppt":
                return "application/mspowerpoint";
            case ".dwg":
                return "image/vnd.dwg";
            case ".msg":
                return "application/msoutlook";
            case ".xml":
            case ".sdxl":
                return "application/xml";
            case ".xdp":
                return "application/vnd.adobe.xdp+xml";
            default:
                return "application/octet-stream";
        }
    }

nun, wenn der button geklickt wird, sollte die Datei vom server heruntergeladen, auf dem lokalen host-computer... aber es scheint nichts passiert zu sein...

habe ich die test.txt auf dem desktop des Server... die Datei speichern option, auch nicht auf der client-Seite..

Veröffentliche ich die Dateien und legen Sie es in den inetpub Ordner des Servers, und führen Sie die GUI der client-Seite.. alles funktioniert, außer dieser...

Anregungen...bitte helfen

dieses Programm lädt eine Datei, wenn es vorhanden ist in dem Ordner inetpub.. vielmehr will ich download von einem beliebigen Standort innerhalb des Servers...

??

InformationsquelleAutor user175084 | 2010-01-05

Schreibe einen Kommentar