.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
SP
satyapriyanayak
Subhransu Sekhar Jena
abhays
DotnetUser

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

upload image file in windows application

Posted By: Mohan Raut     Posted Date: September 09, 2008    Points:2   Category :Windows Application
I have created one windows application where i need to upload image files from local machine and i will store them in a project folder...
at the same time i will write those entries to xml file...so that i can display those entries in a gridview control...
and i am basically from asp.net, so i am not aware of windows form..
i need the code to upload images in windows form...
thnx in advance.

Responses
Author: Faizal             
Posted Date: September 09, 2008     Points: 5   

If you are looking for copying file in Interanet zone try this link

http://www.dotnetspark.com/DotNetForum/17-how-to-copy-a-file-from-server-to-local-system.aspx

Author: Mohan Raut             
Posted Date: September 09, 2008     Points: 5   

No yaar, i want to upload file, for that i have created one button with textbox, on button click i opening the open dialog box with image file format filters(jpg,gif,bmp,etc) now when i select the image file it will show the image path in textbox control....
now i have image path and path where i want to store the image...
and one webclient.upload method....i am jammed how to use this?
plz reply

Author: Pankaj Mishra             
Posted Date: September 09, 2008     Points: 5   

Hi Mohan,
Where you want to upload file? Where is server located? You want to save image within internet or intra net? If its internet then you have to use TCP to upload image in the server you and if its id intra net then Faizal reference is correct.

Cheers
Pankaj

Author: Mohan Raut             
Posted Date: September 10, 2008     Points: 5   

this is my code,
private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
WebClient myWebClient = new WebClient();
string fileName = textBox1.Text;
string _path = Application.StartupPath;
MessageBox.Show(_path);
_path = _path.Replace("Debug", "Images");
MessageBox.Show(_path);
myWebClient.UploadFile(_path,fileName);
}

private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofDlg = new OpenFileDialog();
ofDlg.Filter = "JPG|*.jpg|GIF|*.gif|PNG|*.png|BMP|*.bmp";
if (DialogResult.OK == ofDlg.ShowDialog())
{
textBox1.Text = ofDlg.FileName;
button1.Enabled = true;
}
else
{
MessageBox.Show("Go ahead, select a file!");
}

}

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
button1.Enabled = false;
}
}
i am asp.net developer, the way we use file upload control in webform or any uplaoder, i want exactly the same way.
may be i am able to explain what i need to do,
on the button browse click event open dialog will open from wher i willl choose one file and there is second button upload after clicking the upload that file will get stored in my project folder named "images" this task is very easy in webapplication but i am new to windows application that why i am irritating u.
plz answer me..

Author: Shashi Ray             
Posted Date: September 10, 2008     Points: 5   

http://www.dotnetspark.com/DotNetResource/41-file-upload-with-c-sharp.aspx

Shashi Kant Ray
Author: Shashi Ray             
Posted Date: September 10, 2008     Points: 5   

http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspx

Shashi Kant Ray
Author: Shashi Ray             
Posted Date: September 10, 2008     Points: 5   

http://www.c-sharpcorner.com/UploadFile/munnamax/FileUploader02102006073548AM/FileUploader.aspx?ArticleID=c6caab38-acc1-40c6-a5ef-c2ad639bcecb

Shashi Kant Ray
Author: Pankaj Mishra             
Posted Date: September 10, 2008     Points: 5   

Hi Mohan,
In web application your way is right but in windows application you have to use "Copy" Method to save file in your Image folder.

Let me know if you still have doubt

Cheers
Pankaj

Author: aamir             
Posted Date: December 28, 2008     Points: 5   

plz use code before giving code here
like
{
}

{
}

Author: krishana singh             
Posted Date: December 07, 2010     Points: 5   

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
WebClient myWebClient = new WebClient();
string fileName = textBox1.Text;
string _path = Application.StartupPath;
MessageBox.Show(_path);
_path = _path.Replace("Debug", "Images");
MessageBox.Show(_path);
myWebClient.UploadFile(_path,fileName);
}

private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofDlg = new OpenFileDialog();
ofDlg.Filter = "JPG|*.jpg|GIF|*.gif|PNG|*.png|BMP|*.bmp";
if (DialogResult.OK == ofDlg.ShowDialog())
{
textBox1.Text = ofDlg.FileName;
button1.Enabled = true;
}
else
{
MessageBox.Show("Go ahead, select a file!");
}

}

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
button1.Enabled = false;
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend