C# .NET - How to give default file path in Textbox of fileUpload

Asked By masuri suhasini on 04-Aug-09 02:07 AM

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

 

 

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

 

            }

        }

RE - Ravenet Rasaiyah replied to masuri suhasini on 04-Aug-09 02:54 AM

Hi

I think you can't set it , if you need you need extent file upload control. the reason is its read only.

Thank you


Harry L replied to masuri suhasini on 04-Aug-09 04:19 AM

Hi,

Check the following url for creating custom file upload control with default file path.

http://www.15seconds.com/issue/010504.htm

Regards,

harry

check this - sri sri replied to masuri suhasini on 04-Aug-09 05:17 AM

hi,

you cannot assign value to file upload control.

Instead you have to try with custom file upload control