Click here to Skip to main content
15,113,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys, I have a one FileUpload Control , one Button and TextBox.When clicking on the FileUpload control,we can getting the file URl. After that clicking the Button getting the perticular file Content into TextBox.

Problem is when clicking the Button getting the data into TextBox and same time URL also cleared. How to Stop the clearing the Url in fileUpload control.

C#
protected void btnGet_Click(object sender, EventArgs e)
   {

       if (FUBrowse.HasFile)
       {
           string path = FUBrowse.PostedFile.FileName;
           this.FUBrowse.SaveAs(path);
           this.txtJobDescription.Text = ShowContent(path);
       }

   }
   public string ShowContent(string path)
   {
       string strInput = "";
       string GetStream = "";

       if (File.Exists(path))
       {
           StreamReader sr = new StreamReader(path, UnicodeEncoding.GetEncoding("UTF-8"));
           strInput = sr.ReadLine();
           while (strInput != null)
           {
               GetStream += strInput;
               strInput = sr.ReadLine();
           }
           sr.Close();
       }
       else
       {
           Response.Write("file does not exist!");
       }
       return GetStream;
   }



Please any one Help me.
Posted
Updated 14-Nov-12 19:55pm
v2

1 solution

dear,

You can solve this issue by
C#
string path = FUBrowse.PostedFile.FileName;
            string serverPath = HttpContext.Current.Server.MapPath("~/");
            path = serverPath + path;
            this.FUBrowse.SaveAs(path);
            this.txtJobDescription.Text = ShowContent(path);
   
Comments
CH Guravaiah 15-Nov-12 2:05am
   
thanks for giving reply.But here problem is string path = FUBrowse.PostedFile.FileName; this code getting the URL from HardDisk. string serverPath = HttpContext.Current.Server.MapPath("~/"); this code getting the URL from Solution Explorer. finally i getting the "file does not exist!"; message.Is there any other solution
Varun_Kumar 15-Nov-12 4:00am
   
In asp.net we use file browser this way. But in windows OpenFileDialog will give full path.

Then why you calling the method
this.FUBrowse.SaveAs(path);
This code used for saving browsed file to specified path, here specified path is "path" variable.

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