Search code examples
asp.nethttppostedfile

I want to upload file to HttpPostedFile which is present in "images" folder of my asp.net website


How to assign image present in "images" folder of my asp.net website to HttpPostedFile?


Solution

  • HttpPostedFile is simply used by the ASP.NET FileUpload control by uploaded files only.

    You can't assign a file to this class nor can you inherit from this class since it's sealed.

    What you can do though, is create a similar class that has the following properties/functions:

    public void SaveAs(string filename);
    
    public string FileName { get; set; }
    
    public string ContentType { get; set; }
    
    public int ContentLength { get; set; }
    
    public Stream InputStream { get; set; }