Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<%@ WebHandler Language="C#" Class="dlde" %>

using System;
using System.Web;

public class dlde : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        var fileName = @"D:\Error.txt";
        var r = context.Response;
        r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
        r.ContentType = "text/plain";
        r.WriteFile(context.Server.MapPath(fileName));
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}



I want to download the .txt file from the server system from the specified directory...i tried with this code,but i am getting error,invalid virtual path..How to get the file ,from the server system ..please help me...
Posted
Comments
ravikhoda 24-Feb-14 7:43am    
try server.mappath and not the actual path.

1 solution

First your file should be a virtual path relative to your IIS location, like: "\\Content\\Doc\\Error.txt", and the file must exist with this name on your web Server.
Then you should invoke r.End(); after r.WriteFile(...);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900