Click here to Skip to main content
12,452,066 members (26,183 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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.

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 14-Nov-12 18:50pm
Updated 14-Nov-12 18:55pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

dear,

You can solve this issue by
string path = FUBrowse.PostedFile.FileName;
            string serverPath = HttpContext.Current.Server.MapPath("~/");
            path = serverPath + path;
            this.FUBrowse.SaveAs(path);
            this.txtJobDescription.Text = ShowContent(path);
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100