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. Upload pdf file in MySQL....

Upload pdf file in MySQL....

Scheduled Pinned Locked Moved C#
csharpdatabaseasp-netmysqllinq
9 Posts 4 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.
  • M Offline
    M Offline
    Member 12016106
    wrote on last edited by
    #1

    I wanted to upload my pdf files in MySQL and view from datagrid.... I have an error...This is the error.. "

    Additional information: Could not find a part of the path 'C:\WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction

    " asp.net:

    <asp:Button ID="btn_upload" runat="server" style="z-index: 1; left: 610px; top: 337px; position: absolute; height: 23px; width: 63px" Text="Upload" OnClick="btn_upload_Click" />
    <!---GridView----->
    <div>
    <asp:GridView ID="workinstruc" CssClass="Gridview" runat="server" AutoGenerateColumns="false" DataKeyNames="FileView" >
    <HeaderStyle BackColor="#df5015" />
    <Columns>
    <asp:BoundField DataField="ID" HeaderText="ID" />
    <asp:BoundField DataField="FileName" HeaderText="FileName" />
    <asp:TemplateField HeaderText="FileView">
    <ItemTemplate>
    <asp:LinkButton ID="lnkView" runat="server" Text="View" ></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    <!--End GridView--->

    c#:

    <pre lang="cs">using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Diagnostics;
    using System.Windows.Forms;
    using System.Data;
    using MySql.Data.MySqlClient;

    namespace wsmfgit
    {
    public partial class workinstruction : System.Web.UI.Page

    {
    
        /// &lt;connect DB&gt;
        protected void Page\_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.BindGrid();
            }
        }
        private void BindGrid()
        {
            string constr = @&quot;Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client&quot;;
            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand(&quot;SELECT ID, FileName, FileView FROM work\_inst&quot;))
                {
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        cmd.Connection = con;
    
    CHill60C P Richard DeemingR 3 Replies Last reply
    0
    • M Member 12016106

      I wanted to upload my pdf files in MySQL and view from datagrid.... I have an error...This is the error.. "

      Additional information: Could not find a part of the path 'C:\WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction

      " asp.net:

      <asp:Button ID="btn_upload" runat="server" style="z-index: 1; left: 610px; top: 337px; position: absolute; height: 23px; width: 63px" Text="Upload" OnClick="btn_upload_Click" />
      <!---GridView----->
      <div>
      <asp:GridView ID="workinstruc" CssClass="Gridview" runat="server" AutoGenerateColumns="false" DataKeyNames="FileView" >
      <HeaderStyle BackColor="#df5015" />
      <Columns>
      <asp:BoundField DataField="ID" HeaderText="ID" />
      <asp:BoundField DataField="FileName" HeaderText="FileName" />
      <asp:TemplateField HeaderText="FileView">
      <ItemTemplate>
      <asp:LinkButton ID="lnkView" runat="server" Text="View" ></asp:LinkButton>
      </ItemTemplate>
      </asp:TemplateField>
      </Columns>
      </asp:GridView>
      <!--End GridView--->

      c#:

      <pre lang="cs">using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.IO;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Diagnostics;
      using System.Windows.Forms;
      using System.Data;
      using MySql.Data.MySqlClient;

      namespace wsmfgit
      {
      public partial class workinstruction : System.Web.UI.Page

      {
      
          /// &lt;connect DB&gt;
          protected void Page\_Load(object sender, EventArgs e)
          {
              if (!this.IsPostBack)
              {
                  this.BindGrid();
              }
          }
          private void BindGrid()
          {
              string constr = @&quot;Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client&quot;;
              using (MySqlConnection con = new MySqlConnection(constr))
              {
                  using (MySqlCommand cmd = new MySqlCommand(&quot;SELECT ID, FileName, FileView FROM work\_inst&quot;))
                  {
                      using (MySqlDataAdapter sda = new MySqlDataAdapter())
                      {
                          cmd.Connection = con;
      
      CHill60C Offline
      CHill60C Offline
      CHill60
      wrote on last edited by
      #2

      Well the error is quite clear - the path

      C:\WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction

      does not exist or the account that you are running this under does not have access to that folder. For example, if you are running this on a server you won't have access to "C:\..." - Try using relative pathnames Are you sure that the path is correctly constructed? The repeated sequence WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit looks as if something has gone wong

      M 1 Reply Last reply
      0
      • M Member 12016106

        I wanted to upload my pdf files in MySQL and view from datagrid.... I have an error...This is the error.. "

        Additional information: Could not find a part of the path 'C:\WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction

        " asp.net:

        <asp:Button ID="btn_upload" runat="server" style="z-index: 1; left: 610px; top: 337px; position: absolute; height: 23px; width: 63px" Text="Upload" OnClick="btn_upload_Click" />
        <!---GridView----->
        <div>
        <asp:GridView ID="workinstruc" CssClass="Gridview" runat="server" AutoGenerateColumns="false" DataKeyNames="FileView" >
        <HeaderStyle BackColor="#df5015" />
        <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" />
        <asp:BoundField DataField="FileName" HeaderText="FileName" />
        <asp:TemplateField HeaderText="FileView">
        <ItemTemplate>
        <asp:LinkButton ID="lnkView" runat="server" Text="View" ></asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>
        <!--End GridView--->

        c#:

        <pre lang="cs">using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.IO;
        using System.Web;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Diagnostics;
        using System.Windows.Forms;
        using System.Data;
        using MySql.Data.MySqlClient;

        namespace wsmfgit
        {
        public partial class workinstruction : System.Web.UI.Page

        {
        
            /// &lt;connect DB&gt;
            protected void Page\_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
                    this.BindGrid();
                }
            }
            private void BindGrid()
            {
                string constr = @&quot;Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client&quot;;
                using (MySqlConnection con = new MySqlConnection(constr))
                {
                    using (MySqlCommand cmd = new MySqlCommand(&quot;SELECT ID, FileName, FileView FROM work\_inst&quot;))
                    {
                        using (MySqlDataAdapter sda = new MySqlDataAdapter())
                        {
                            cmd.Connection = con;
        
        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        The reason you're having a problem is because you're using Server.MapPath along with mapping to a specific address. Do one, or the other, and not both.

        M 1 Reply Last reply
        0
        • M Member 12016106

          I wanted to upload my pdf files in MySQL and view from datagrid.... I have an error...This is the error.. "

          Additional information: Could not find a part of the path 'C:\WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction

          " asp.net:

          <asp:Button ID="btn_upload" runat="server" style="z-index: 1; left: 610px; top: 337px; position: absolute; height: 23px; width: 63px" Text="Upload" OnClick="btn_upload_Click" />
          <!---GridView----->
          <div>
          <asp:GridView ID="workinstruc" CssClass="Gridview" runat="server" AutoGenerateColumns="false" DataKeyNames="FileView" >
          <HeaderStyle BackColor="#df5015" />
          <Columns>
          <asp:BoundField DataField="ID" HeaderText="ID" />
          <asp:BoundField DataField="FileName" HeaderText="FileName" />
          <asp:TemplateField HeaderText="FileView">
          <ItemTemplate>
          <asp:LinkButton ID="lnkView" runat="server" Text="View" ></asp:LinkButton>
          </ItemTemplate>
          </asp:TemplateField>
          </Columns>
          </asp:GridView>
          <!--End GridView--->

          c#:

          <pre lang="cs">using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.IO;
          using System.Web;
          using System.Web.UI;
          using System.Web.UI.WebControls;
          using System.Diagnostics;
          using System.Windows.Forms;
          using System.Data;
          using MySql.Data.MySqlClient;

          namespace wsmfgit
          {
          public partial class workinstruction : System.Web.UI.Page

          {
          
              /// &lt;connect DB&gt;
              protected void Page\_Load(object sender, EventArgs e)
              {
                  if (!this.IsPostBack)
                  {
                      this.BindGrid();
                  }
              }
              private void BindGrid()
              {
                  string constr = @&quot;Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client&quot;;
                  using (MySqlConnection con = new MySqlConnection(constr))
                  {
                      using (MySqlCommand cmd = new MySqlCommand(&quot;SELECT ID, FileName, FileView FROM work\_inst&quot;))
                      {
                          using (MySqlDataAdapter sda = new MySqlDataAdapter())
                          {
                              cmd.Connection = con;
          
          Richard DeemingR Online
          Richard DeemingR Online
          Richard Deeming
          wrote on last edited by
          #4

          Member 12016106 wrote:

          Server.MapPath(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf" + filename)

          The Server.MapPath method expects a virtual path within the current application. It should look something like:

          Server.MapPath("~/workinstruction/pdf/" + filename)

          You've passed in a physical UNC path, which won't work. If you want to save the file in the UNC path, don't use Server.MapPath:

          FileUpload1.SaveAs(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf" + filename);

          Member 12016106 wrote:

          cmd.Parameters.AddWithValue(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf", filename);

          Your query doesn't have a parameter with the name \\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf. I suspect you meant to pass that as the path:

          cmd.Parameters.AddWithValue("@Path", @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf");


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          M 1 Reply Last reply
          0
          • CHill60C CHill60

            Well the error is quite clear - the path

            C:\WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction

            does not exist or the account that you are running this under does not have access to that folder. For example, if you are running this on a server you won't have access to "C:\..." - Try using relative pathnames Are you sure that the path is correctly constructed? The repeated sequence WSmfgIT\WSmfgIT\WSmfgIT\wsmfgit\wsmfgit looks as if something has gone wong

            M Offline
            M Offline
            Member 12016106
            wrote on last edited by
            #5

            my actual path is this :

            @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf"

            1 Reply Last reply
            0
            • P Pete OHanlon

              The reason you're having a problem is because you're using Server.MapPath along with mapping to a specific address. Do one, or the other, and not both.

              M Offline
              M Offline
              Member 12016106
              wrote on last edited by
              #6

              this is my path

              @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf"

              so how should I declare it? can you pls help me..

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Member 12016106 wrote:

                Server.MapPath(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf" + filename)

                The Server.MapPath method expects a virtual path within the current application. It should look something like:

                Server.MapPath("~/workinstruction/pdf/" + filename)

                You've passed in a physical UNC path, which won't work. If you want to save the file in the UNC path, don't use Server.MapPath:

                FileUpload1.SaveAs(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf" + filename);

                Member 12016106 wrote:

                cmd.Parameters.AddWithValue(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf", filename);

                Your query doesn't have a parameter with the name \\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf. I suspect you meant to pass that as the path:

                cmd.Parameters.AddWithValue("@Path", @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf");


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                M Offline
                M Offline
                Member 12016106
                wrote on last edited by
                #7

                I have try what you mentioned above but I still have an error... this is the error:

                An exception of type 'System.InvalidOperationException' occurred in MySql.Data.dll but was not handled in user code

                Additional information: Connection must be valid and open.

                c#:

                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.IO;
                using System.Web;
                using System.Web.UI;
                using System.Web.UI.WebControls;
                using System.Diagnostics;
                using System.Windows.Forms;
                using System.Data;
                using MySql.Data.MySqlClient;

                namespace wsmfgit
                {
                public partial class workinstruction : System.Web.UI.Page

                {
                
                    /// <connect DB>
                    protected void Page\_Load(object sender, EventArgs e)
                    {
                        if (!this.IsPostBack)
                        {
                            this.BindGrid();
                        }
                    }
                    private void BindGrid()
                    {
                        string constr = @"Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client";
                        using (MySqlConnection con = new MySqlConnection(constr))
                        {
                            using (MySqlCommand cmd = new MySqlCommand("SELECT ID, FileName, FileView FROM work\_inst"))
                            {
                                using (MySqlDataAdapter sda = new MySqlDataAdapter())
                                {
                                    cmd.Connection = con;
                                    sda.SelectCommand = cmd;
                                    using (DataTable dt = new DataTable())
                                    {
                                        sda.Fill(dt);
                                        workinstruc.DataSource = dt;
                                        workinstruc.DataBind();
                                    }
                                }
                            }
                        }
                    }
                    ///</connect>
                    /// <link to home button>
                    protected void imgbtn\_home\_Click(object sender, ImageClickEventArgs e)
                    {
                        Response.Redirect("default.aspx");
                    }
                
                    protected void btn\_upload\_Click(object sender, EventArgs e)
                    {
                        string constr = @"Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client";
                        using (MySqlConnection con = new MySqlConnection(constr))
                        {
                        string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
                        FileUpload1.SaveAs(@"\\\\192.168.5.10\\fbar\\TOOLS\\ProbingApps\\ProbingSystem\\workinstruction\\pdf" + filename);
                        con.Open();
                
                Richard DeemingR 1 Reply Last reply
                0
                • M Member 12016106

                  I have try what you mentioned above but I still have an error... this is the error:

                  An exception of type 'System.InvalidOperationException' occurred in MySql.Data.dll but was not handled in user code

                  Additional information: Connection must be valid and open.

                  c#:

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.IO;
                  using System.Web;
                  using System.Web.UI;
                  using System.Web.UI.WebControls;
                  using System.Diagnostics;
                  using System.Windows.Forms;
                  using System.Data;
                  using MySql.Data.MySqlClient;

                  namespace wsmfgit
                  {
                  public partial class workinstruction : System.Web.UI.Page

                  {
                  
                      /// <connect DB>
                      protected void Page\_Load(object sender, EventArgs e)
                      {
                          if (!this.IsPostBack)
                          {
                              this.BindGrid();
                          }
                      }
                      private void BindGrid()
                      {
                          string constr = @"Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client";
                          using (MySqlConnection con = new MySqlConnection(constr))
                          {
                              using (MySqlCommand cmd = new MySqlCommand("SELECT ID, FileName, FileView FROM work\_inst"))
                              {
                                  using (MySqlDataAdapter sda = new MySqlDataAdapter())
                                  {
                                      cmd.Connection = con;
                                      sda.SelectCommand = cmd;
                                      using (DataTable dt = new DataTable())
                                      {
                                          sda.Fill(dt);
                                          workinstruc.DataSource = dt;
                                          workinstruc.DataBind();
                                      }
                                  }
                              }
                          }
                      }
                      ///</connect>
                      /// <link to home button>
                      protected void imgbtn\_home\_Click(object sender, ImageClickEventArgs e)
                      {
                          Response.Redirect("default.aspx");
                      }
                  
                      protected void btn\_upload\_Click(object sender, EventArgs e)
                      {
                          string constr = @"Data Source=192.168.8.124; Database=pmdb; User ID=client; Password=client";
                          using (MySqlConnection con = new MySqlConnection(constr))
                          {
                          string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
                          FileUpload1.SaveAs(@"\\\\192.168.5.10\\fbar\\TOOLS\\ProbingApps\\ProbingSystem\\workinstruction\\pdf" + filename);
                          con.Open();
                  
                  Richard DeemingR Online
                  Richard DeemingR Online
                  Richard Deeming
                  wrote on last edited by
                  #8

                  In your btn_upload_Click method, you've not set the command's connection property.


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  M 1 Reply Last reply
                  0
                  • Richard DeemingR Richard Deeming

                    In your btn_upload_Click method, you've not set the command's connection property.


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    M Offline
                    M Offline
                    Member 12016106
                    wrote on last edited by
                    #9

                    Thank You soo much for your kind explanation.. I got the answer..

                    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