Finding the location of a text file using Fileupload

Last post 10-22-2008 4:07 AM by anas. 4 replies.

Sort Posts:

  • Finding the location of a text file using Fileupload

    10-21-2008, 10:43 AM
    • Member
      point Member
    • warped576
    • Member since 10-21-2008, 2:22 PM
    • Posts 2

     Hi all,

    If got myself a bit stuck. I'm writing an application that reads a header dump in the form of a text file. I've got it working and can select the location of the text file by getting the user to manually input the directory into a textbox however, i want to make it a bit more friendly.  I've been trying to use methods of the 'fileupload' class to make use of the browse ability. unfortunaly it will only read in file that are placed in the 'Microsoft Visual Studio 9.0\Common7\IDE\' directory.

    Here's what if got when reading in the file.....

              

      /*---Check valid file has been selected---*/
                if (FileUpload1.HasFile)
                {
                    /*--- No error if file presesnt ---*/
                    load_feedback.Text = " ";

                    /*--- Get the full path of file on computer ---*/
                    string strFileNameWithPath = FileUpload1.PostedFile.FileName;

                    /*--- Get the extension name of the file ---*/
                    string strExtensionName = System.IO.Path.GetExtension(strFileNameWithPath);
                    
                    /*---Read text from file into string---*/
                    using (StreamReader rdr = File.OpenText(strFileNameWithPath))
                    {
                        string input_from_file = rdr.ReadToEnd();
                        input_from_file = input_from_file.Trim();   //trim white spaces from start and end


                 .

                 .

                 .

                  /*--- Close the stream ---*/
                  rdr.Close();
              }

     

    Any help appreciated :)

     

  • Re: Finding the location of a text file using Fileupload

    10-21-2008, 12:04 PM
    • All-Star
      36,931 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,964

     Are you trying to navigate files and folders on the server or on the clients computer?

    Because of security restrictions there is no way for you to access the clients computer. Literally the only way can access it is with the file upload component. You cant automate it or force a selection because it could trick users to browser manufacturers did not include it. You can read the structure of their hard drive either.

  • Re: Finding the location of a text file using Fileupload

    10-21-2008, 6:29 PM
    • All-Star
      60,921 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,865
    • Moderator

     I didn't Understood ,

    Is the Files Placed on the server ? Or on the client computer ?

    Can you explain the problem more clearly .

    Regards,

    Anas Ghanem | Blog

  • Re: Finding the location of a text file using Fileupload

    10-22-2008, 3:54 AM
    • Member
      point Member
    • warped576
    • Member since 10-21-2008, 2:22 PM
    • Posts 2

    Yeh the files on the client computer.

     

    It's a web application that parses a human unfriendly header dump with values in a db to provide a friendly output. The user supplies the hd in the form of a text file that the app reads from. I was hoping the upload method would be a nice way of the user to point to the file without having to write the directory into a textbox, but obviously it's not feesible.

     Thanks for your help Smile

     Edd

  • Re: Finding the location of a text file using Fileupload

    10-22-2008, 4:07 AM
    Answer
    • All-Star
      60,921 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,865
    • Moderator

     Looks like you need to use FileUpload control to allow the user to browse his/her local machine folders and select the File that he/she want to upload ,

    Take a look at fileUpload tutorials :

    http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/standard/fileupload.aspx

    http://www.dotnet-webhosting.com/aspnet-2-0-tutorials/asp-net-2-0-fileupload.aspx

     

    Regards,

    Anas Ghanem | Blog

Page 1 of 1 (5 items)