i have a application wherein i have a browse button. when i click tht button it says index outofrange exception. i want to search for the file add that file to the form and mail through the windows form. sending mail through the form is working fine.
this is my code in the browse button click code:
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "MyComputer Open File Dialog";
fdlg.InitialDirectory = "C:\\";
fdlg.Filter = "All files(*.*)|*.*|All files(*.*)|*.*";
fdlg.RestoreDirectory = true;
txtAttachment.Text = fdlg.FileName;
//mail.Attachments.Add(new Attachment("C:\\Users\\Avinash\\Documents\\Desktop\\total_police_station_numbers.txt"));
}
please help me in this regard.
Thanks in advance,
Avinash
Loading
Raja KrishnamurthyPosted Mar 8, 2011, 10:55 AM
http://msdn.microsoft.com/en-us/library/aa984392%28VS.71%29.aspx
HTH.
Happy Programming!!!
Regards,
Raja
Amit ChoudharyPosted Mar 8, 2011, 10:16 AM
use below snippet in your code..
string path="C:\\Users\\Avinash\\Documents\\Desktop\\total_police_station_numbers.txt";
If(File.Exists(path))
{
txtAttachment.Text = fdlg.FileName;
mail.Attachments.Add(new Attachment(path));
}
else
{
//Throw some exception or send message to use that file does not exist
}
Hope this helps you.
Thanks.
Soft CornerPosted Mar 8, 2011, 1:56 AM
Checkout this rar , Which contain an example of file browsing in windows forms
Krishna GaradPosted Mar 8, 2011, 12:58 AM