You must Sign In to post a response.
  • Category: .NET

    How to give default file path in textbox of fileupload

    Hi,
    I am working on c# 2.0 web application. Im my application I have to upload file from client machine to server machine .
    So I am using file upload control to upload file.
    I have to give default file to upload("C:\EmailPrisma1\test.txt") .without using browse button.
    How to give default file path in Textbox of fileUpload

    error:
    FileUpload1.FileName = clientfilepath;
    Property or indexer 'System.Web.UI.WebControls.FileUpload.FileName' cannot be assigned to -- it is read only



    string msg;
    if (FileUpload1.HasFile)
    try
    {
    string clientfilepath = "";
    clientfilepath = Request.QueryString["FilePath"];
    //FileInput.PostedFile.SaveAs(MapPath(".") + serverFileName);
    //FileInput.PostedFile.FileName == ""
    clientfilepath = @"C:\EmailPrisma1\test.txt";
    FileUpload1.FileName = clientfilepath;
    Property or indexer 'System.Web.UI.WebControls.FileUpload.FileName' cannot be assigned to -- it is read only
    FileUpload1.SaveAs("C:\\EmailPrisma1\\" + FileUpload1.FileName);
    msg = "File name: " +
    FileUpload1.PostedFile.FileName + "<br>" +
    FileUpload1.PostedFile.ContentLength + " kb<br>" +
    "Content type: " +
    FileUpload1.PostedFile.ContentType;
    }
    catch (Exception ex)
    {
    msg = "ERROR: " + ex.Message.ToString();

    }
    else
    {
    msg = "You have not specified a file.";

    }
    }
  • #409660
    File upload --> File Name is ReadOnly and We can not assign a default value to FileUpload control.


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.