Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ASP C# WebSite to load a simple CSV File

ASP C# WebSite to load a simple CSV File

Scheduled Pinned Locked Moved C#
sysadmincsharphelp
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gorovdude
    wrote on last edited by
    #1

    Hi All, I want to have an ASP C# WebSite that loads a simple CSV File and present it in a GridView control (at least for a start). I already have a piece of code that do almost all of the work, what i miss / unable to make it work is setting correctly the "Data Source". The CSV file that I want to load is located on different server in the network (path is "\\td47vc\public\Joe\ASP\Test"). Here is the code I wrote:

    public DataSet GetCSVFile(string fileName)
    {
    
        string pathName = "\\\\td47vc\\\\public\\\\Joe\\\\ASP\\\\Test";
        string file = System.IO.Path.GetFileName(fileName);
        OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
        OleDbCommand excelCommand = new OleDbCommand(@"SELECT \* FROM " + file, excelConnection);
        OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
        excelConnection.Open();
        DataSet ds = new DataSet();
        excelAdapter.Fill(ds);
        excelConnection.Close();
        return ds;
    }
    

    I get the following error:

    '\\td47vc\public\Joe\ASP\Test' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

    Thanks, GorovDude

    D T A M 4 Replies Last reply
    0
    • G gorovdude

      Hi All, I want to have an ASP C# WebSite that loads a simple CSV File and present it in a GridView control (at least for a start). I already have a piece of code that do almost all of the work, what i miss / unable to make it work is setting correctly the "Data Source". The CSV file that I want to load is located on different server in the network (path is "\\td47vc\public\Joe\ASP\Test"). Here is the code I wrote:

      public DataSet GetCSVFile(string fileName)
      {
      
          string pathName = "\\\\td47vc\\\\public\\\\Joe\\\\ASP\\\\Test";
          string file = System.IO.Path.GetFileName(fileName);
          OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
          OleDbCommand excelCommand = new OleDbCommand(@"SELECT \* FROM " + file, excelConnection);
          OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
          excelConnection.Open();
          DataSet ds = new DataSet();
          excelAdapter.Fill(ds);
          excelConnection.Close();
          return ds;
      }
      

      I get the following error:

      '\\td47vc\public\Joe\ASP\Test' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

      Thanks, GorovDude

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      Well you could try: 0)

      @"\\td47vc\public\Joe\ASP\Test";

      1. Using the IP of the server instead of the server name (10.xx.xx.xx instead of \\someserver01). Maybe it's on a different VLAN and it does not know it by name 2) If it still doesn't work then it's clearly a matter of credentials/rights. That one only you and/or the admin can fix. :)

      I used to think.... Finally I realized it's no good.

      modified on Tuesday, December 7, 2010 4:28 AM

      L 1 Reply Last reply
      0
      • D Dan Mos

        Well you could try: 0)

        @"\\td47vc\public\Joe\ASP\Test";

        1. Using the IP of the server instead of the server name (10.xx.xx.xx instead of \\someserver01). Maybe it's on a different VLAN and it does not know it by name 2) If it still doesn't work then it's clearly a matter of credentials/rights. That one only you and/or the admin can fix. :)

        I used to think.... Finally I realized it's no good.

        modified on Tuesday, December 7, 2010 4:28 AM

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        do you really want double backslashes everywhere? :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.

        D 1 Reply Last reply
        0
        • L Luc Pattyn

          do you really want double backslashes everywhere? :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          Nice. I missed it completely. Just focused on the start. Fixed. :)

          I used to think.... Finally I realized it's no good.

          L 1 Reply Last reply
          0
          • D Dan Mos

            Nice. I missed it completely. Just focused on the start. Fixed. :)

            I used to think.... Finally I realized it's no good.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            you'll have to try again I'm afraid, if you want a double backslash, either give four, or use '@'; three backslashes is no good. I prefer the '@' approach, as that takes and shows the string as intended. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.

            D 1 Reply Last reply
            0
            • L Luc Pattyn

              you'll have to try again I'm afraid, if you want a double backslash, either give four, or use '@'; three backslashes is no good. I prefer the '@' approach, as that takes and shows the string as intended. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.

              D Offline
              D Offline
              Dan Mos
              wrote on last edited by
              #6

              Yep that's what I did. Just before you fixed my "code" the second time :laugh: I guess I'm better of just fooling around. :)

              I used to think.... Finally I realized it's no good.

              L 1 Reply Last reply
              0
              • D Dan Mos

                Yep that's what I did. Just before you fixed my "code" the second time :laugh: I guess I'm better of just fooling around. :)

                I used to think.... Finally I realized it's no good.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                looking great now. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.

                1 Reply Last reply
                0
                • G gorovdude

                  Hi All, I want to have an ASP C# WebSite that loads a simple CSV File and present it in a GridView control (at least for a start). I already have a piece of code that do almost all of the work, what i miss / unable to make it work is setting correctly the "Data Source". The CSV file that I want to load is located on different server in the network (path is "\\td47vc\public\Joe\ASP\Test"). Here is the code I wrote:

                  public DataSet GetCSVFile(string fileName)
                  {
                  
                      string pathName = "\\\\td47vc\\\\public\\\\Joe\\\\ASP\\\\Test";
                      string file = System.IO.Path.GetFileName(fileName);
                      OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
                      OleDbCommand excelCommand = new OleDbCommand(@"SELECT \* FROM " + file, excelConnection);
                      OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
                      excelConnection.Open();
                      DataSet ds = new DataSet();
                      excelAdapter.Fill(ds);
                      excelConnection.Close();
                      return ds;
                  }
                  

                  I get the following error:

                  '\\td47vc\public\Joe\ASP\Test' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

                  Thanks, GorovDude

                  T Offline
                  T Offline
                  TweakBird
                  wrote on last edited by
                  #8

                  See this[^].it might be helpful.

                  1 Reply Last reply
                  0
                  • G gorovdude

                    Hi All, I want to have an ASP C# WebSite that loads a simple CSV File and present it in a GridView control (at least for a start). I already have a piece of code that do almost all of the work, what i miss / unable to make it work is setting correctly the "Data Source". The CSV file that I want to load is located on different server in the network (path is "\\td47vc\public\Joe\ASP\Test"). Here is the code I wrote:

                    public DataSet GetCSVFile(string fileName)
                    {
                    
                        string pathName = "\\\\td47vc\\\\public\\\\Joe\\\\ASP\\\\Test";
                        string file = System.IO.Path.GetFileName(fileName);
                        OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
                        OleDbCommand excelCommand = new OleDbCommand(@"SELECT \* FROM " + file, excelConnection);
                        OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
                        excelConnection.Open();
                        DataSet ds = new DataSet();
                        excelAdapter.Fill(ds);
                        excelConnection.Close();
                        return ds;
                    }
                    

                    I get the following error:

                    '\\td47vc\public\Joe\ASP\Test' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

                    Thanks, GorovDude

                    A Offline
                    A Offline
                    Alok Sharma ji
                    wrote on last edited by
                    #9

                    what about setting your connection string in web inf instead of code :)

                    G 1 Reply Last reply
                    0
                    • A Alok Sharma ji

                      what about setting your connection string in web inf instead of code :)

                      G Offline
                      G Offline
                      gorovdude
                      wrote on last edited by
                      #10

                      how?

                      1 Reply Last reply
                      0
                      • G gorovdude

                        Hi All, I want to have an ASP C# WebSite that loads a simple CSV File and present it in a GridView control (at least for a start). I already have a piece of code that do almost all of the work, what i miss / unable to make it work is setting correctly the "Data Source". The CSV file that I want to load is located on different server in the network (path is "\\td47vc\public\Joe\ASP\Test"). Here is the code I wrote:

                        public DataSet GetCSVFile(string fileName)
                        {
                        
                            string pathName = "\\\\td47vc\\\\public\\\\Joe\\\\ASP\\\\Test";
                            string file = System.IO.Path.GetFileName(fileName);
                            OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
                            OleDbCommand excelCommand = new OleDbCommand(@"SELECT \* FROM " + file, excelConnection);
                            OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
                            excelConnection.Open();
                            DataSet ds = new DataSet();
                            excelAdapter.Fill(ds);
                            excelConnection.Close();
                            return ds;
                        }
                        

                        I get the following error:

                        '\\td47vc\public\Joe\ASP\Test' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

                        Thanks, GorovDude

                        M Offline
                        M Offline
                        Muhammad Mazhar
                        wrote on last edited by
                        #11

                        Try mapping virtual path to physical path using Server object. For example where you are doing

                        string pathName = "\\td47vc\\public\\Joe\\ASP\\Test";

                        instead do it something like

                        string pathName = Server.MapPath("~/Joe/Asp/Test.csv");

                        Where you need to make sure you are passing correct virtual path to MapPath call. You need to specify it relative to your application root.

                        I Web Development Free Lancer
                        Share your experience with others Check my Blog...

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups