|
 |
|
Copy file in C# ใน Windows XP ไม่ได้ครับ แต่ใน Windows7 กลับไม่มีปัญหาอะไร |
|
 |
|
|
 |
 |
|
เครื่องที่ใช้พัฒนาโปรแกรม เป็น Windows7 ครับ
คือต้องการ Copy file ภายในเครื่องให้ไปอยู่คนละที่ (ไม่ใช้ระบบ network ใดๆ)
พอนำโปรแกรมมารัน (ไม่ผ่าน Visual Studio) ใน Windows7 ก็ไม่มีปัญหาอะไรครับ
แต่พอมารันใน WindowsXP กลับฟ้อง error ทั้งๆที่โปรแกรมก็ชุดเดียวกัน
Error แบบนี้อ่ะครับ (ตามภาพ)

ส่วนโค้ดที่ใช้เขียน
Code (C#)
private void btnExportDb_Click(object sender, EventArgs e)
{
string path = @"master/data_db_2.mdb";
string path2;
saveFileDialog1.FileName = "data_db_2";
saveFileDialog1.Filter = "ฐานข้อมูล|.mdb";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
path2 = saveFileDialog1.FileName;
//MessageBox.Show("showPath to save \n"+path2);
try
{
File.Copy(path, path2);
MessageBox.Show("ส่งออกไฟล์เรียบร้อย", "เสร็จสิ้น", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("ไม่สามารถส่งออกได้ \n" + ex,"ผิดพลาด",MessageBoxButtons.OK,MessageBoxIcon.Error);
//Console.WriteLine("Double copy is not allowed, which was not expected.");
}
}
}
Tag : .NET, C#

|
|
 |
 |
 |
 |
Date :
2012-03-07 16:50:27 |
By :
t2dear_ict3 |
View :
1654 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนโฟเดอร์จัดเก็บเป็นภาษาอังกฤษ ครับ น่าจะได้ 
|
 |
 |
 |
 |
Date :
2012-03-08 11:20:50 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวแปร path เก็บค่าเป็น relative filename เพื่อให้แน่ใจว่า
ไม่ได้เกิดจากปัญหานี้
ให้ลองกำหนดแบบเต็มๆ
เช่น
Code (C#)
string path = @"c:\\master\\data_db_2.mdb";
เพราะเป็นไปได้ว่า เวลารันบน OS ที่ต่างกัน มันจะเข้าใจไม่ตรงกัน
|
 |
 |
 |
 |
Date :
2012-03-08 12:39:40 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขได้แล้วครับ
T^T (ซึ้ง)
แก้ไขโดยเพิ่มไดเรกทอรี่ปัจจุบันที่โปรแกรมรันอยู่ครับ เพื่อให้เห็นเป็น full path
แก้ไขที่บรรทัดที่ 3 ครับ คราวนี้ผ่านฉลุย
Code (C#)
private void btnExportDb_Click(object sender, EventArgs e)
{
string path = Directory.GetCurrentDirectory()+@"master/data_db_2.mdb";
string path2;
saveFileDialog1.FileName = "data_db_2";
saveFileDialog1.Filter = "ฐานข้อมูล|.mdb";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
path2 = saveFileDialog1.FileName;
//MessageBox.Show("showPath to save \n"+path2);
try
{
File.Copy(path, path2);
MessageBox.Show("ส่งออกไฟล์เรียบร้อย", "เสร็จสิ้น", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("ไม่สามารถส่งออกได้ \n" + ex,"ผิดพลาด",MessageBoxButtons.OK,MessageBoxIcon.Error);
//Console.WriteLine("Double copy is not allowed, which was not expected.");
}
}
}
|
 |
 |
 |
 |
Date :
2012-03-08 21:28:19 |
By :
t2dear_ict |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดีใจด้วยครับ
|
 |
 |
 |
 |
Date :
2012-03-08 21:34:19 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|