string username = "";
string password = "";
{
System.Diagnostics.Process.Start(@"\\"folder path"\ foldername");
}
This is my code. How should I access to server. there is username and password for the server. Could anyone help me??
string username = "";
string password = "";
{
System.Diagnostics.Process.Start(@"\\"folder path"\ foldername");
}
This is my code. How should I access to server. there is username and password for the server. Could anyone help me??
So how should declare it to download large size file??
I can download small size of application but could not download big size of application. It shows out of memory. Below is my code:
string Files = ListBox1.SelectedValue;
byte[] fileBytes = System.IO.File.ReadAllBytes(Files);
WebClient User = new WebClient();
byte\[\] FileBuffer = User.DownloadData(Files);
if (FileBuffer != null)
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-length", FileBuffer.Length.ToString());
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(Files));
context.Response.BinaryWrite(FileBuffer);
context.ApplicationInstance.CompleteRequest();
Could pls anyone help...
Thank You soo much for your kind explanation.. I got the answer..
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();
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..
my actual path is this :
@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\workinstruction\pdf"
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;
Thank you for kind sharing. I wanted to display files from server to list box. I also wanted to put search button to search the files. the search button must be search from all directories or subfolders. if the file not exist in the server it must show an alert message. Now, my problem is I do not know how to show alert message in c#...Could you pls help... asp.net code:
<asp:TextBox ID="txtbox_clotho" placeholder="Search by Mac Address" runat="server" Height="21px" style="margin-left: 45px" Width="217px" BorderColor="#333333" BorderStyle="Solid" ></asp:TextBox>
<br />
<asp:Button ID="btn_search" runat="server" BackColor="#006699" BorderColor="Black" BorderStyle="Groove" Font-Bold="True" Font-Size="Medium" ForeColor="White" OnClick="btn_search_Click" style="z-index: 1; left: 279px; top: 58px; position: absolute; height: 30px; width: 74px" Text="Search" />
<br />
<br />
<asp:ListBox ID="lstbox_clotho" runat="server" Height="81px" style="margin-left: 47px" Width="245px" ></asp:ListBox>
<asp:ImageButton ID="imgbtn_dwn" runat="server" ImageUrl="~/images/download.png" Height="49px" Width="50px" OnClick="imgbtn_dwn_Click" />
<br />
c# code:
<pre lang="cs">using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace wsmfgit
{
/// <display files in listbox from directory>
public partial class downloadsoftware : System.Web.UI.Page
{
protected void Page\_Load(object sender, EventArgs e)
{
DirectoryInfo info = new DirectoryInfo(@"\\\\192.168.5.10\\fbar\\TOOLS\\ProbingApps\\ProbingSystem\\DesktopCopyTemp");
FileInfo\[\] Files = info.GetFiles("\*.\*");
foreach (FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
}
///</display>
/// <link to home button&
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections; namespace wsmfgit { /// <display files in listbox from directory> public partial class downloadsoftware : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Directory.CreateDirectory("C:\\DesktopCopyTemp"); DirectoryInfo info = new DirectoryInfo(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\DesktopCopyTemp"); FileInfo[] Files = info.GetFiles("*.*"); foreach (FileInfo file in Files) { ListBox1.Items.Add(file.Name); } } ///</display> /// <link to home button> protected void imgbtn_home_Click(object sender, ImageClickEventArgs e) { Response.Redirect("default.aspx"); } ///</link> ///<software download button1> protected void btn_dwn_Click(object sender, EventArgs e) { string File = ListBox1.SelectedValue; Response.ContentType = ContentType; Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(File)); Response.End(); } /// </software> protected void btn_search_Click(object sender, EventArgs e) { lstbox_clotho.Items.Clear(); string search=txtbox_clotho.Text; if (txtbox_clotho.Text != "") { string[] licfiles = Directory.GetFiles(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\Clotho_License", "*" + txtbox_clotho.Text + "*.lic", SearchOption.AllDirectories); foreach (string file in licfiles) { lstbox_clotho.Items.Add(new ListItem(Path.GetFileName(file), file)); } { txtbox_clotho.Text = ""; } } } protected void imgbtn_dwn_Click(object sender, ImageClickEventArgs e) { string licfiles = lstbox_clotho.SelectedValue; Response.ContentType = ContentType; Response.AppendHeader("Content-Disposition", "attachmen
There is no error. It is not showing any messages..
I wanted to give alert message when the search result is invalid.... I have a code but its not working. Could anyone help me?
protected void btn_search_Click(object sender, EventArgs e)
{
lstbox_clotho.Items.Clear();
string search=txtbox_clotho.Text;
if (txtbox_clotho.Text != "")
{
string[] licfiles = Directory.GetFiles(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\Clotho_License", "*" + txtbox_clotho.Text + "*.lic", SearchOption.AllDirectories);
foreach (string file in licfiles)
{
lstbox_clotho.Items.Add(new ListItem(Path.GetFileName(file), file));
}
{
txtbox\_clotho.Text = "";
}
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}
}
}
protected void btn_dwn_Click(object sender, EventArgs e)
{
string File = ListBox1.SelectedValue;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(File));
Response.End();
}
Now the files are saving in local, downloads folder. I don't want it to happen. I want it to automatically save in c:\ with new folder..... This is my code...Could anyone help me..
Thank You. its really work..
string[] file = null;
int idx;
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\DesktopCopyTemp");
FileInfo[] Files = dinfo.GetFiles("*.txt");
foreach (FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
}
this is the code which shows files directory, and it display on listbox... Now, I want to download files from list box. I'm not sure with the code. please do help me....Thank You.
ok. thank you
I have one more question. is the files can be download to local from listbox? I have looked for it but I did not get any source code for it.
ya, its worked. Thank you so much for the kind share.
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\Users\Probing\Desktop");
FileInfo[] Files = dinfo.GetFiles("*.txt");
foreach (FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
I have the source code but its not displaying anything in the listbox.. can anyone help me why is this so?
Thank you so much for your help. I got the answer. I did not declare file, that's why it shows error. now I'm done.