Click here to Skip to main content
Rate this: bad
good
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 19:50pm
Edited 14-Nov-12 19: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 at 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 at 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
0 DamithSL 295
1 OriginalGriff 214
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 113
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
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