.NET Windows Form ผมต้องการ copy รูปภาพที่ผู้ใช้ browse เลือกไปวางตรงที่อยู่ folder project เรา และแสดงต้องทำแบบไหนครับ ท่านผู้รู้ช่วยแนะนำหน่อยครับ
Code (C#)
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
// Code to write the stream goes here.
myStream.Close();
}
}
}
Code (C#)
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx
Date :
2011-08-27 19:24:58
By :
webmaster
ขอบคุณพี่วินมากครับ
Date :
2011-08-29 09:16:50
By :
AoFzaIT
Load balance : Server 05