Upload pdf file in MySQL....
-
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{ /// <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;
-
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{ /// <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;
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 -
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{ /// <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;
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.
-
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{ /// <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;
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
-
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 wongmy actual path is this :
@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf"
-
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.
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..
-
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
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();
-
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();
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
-
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
Thank You soo much for your kind explanation.. I got the answer..