winform更新中,如何在文件复制完后,再去修改配置文件的版本号 我的问题是这样的:比如说,正在更新的时候突然就断网了,但是东西已经更新了,版本号也被修改了,下次他就不会更新了。怎么解决这个问题啊WinForm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是菜鸟不懂那个啊,winform的代码怎么弄成事务啊 private void Copy(string sourceDirName, string destDirName) { try { if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\") { sourceDirName = sourceDirName + "\\"; } if (destDirName.Substring(destDirName.Length - 1) != "\\") { destDirName = destDirName + "\\"; } if (Directory.Exists(sourceDirName)) { if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } foreach (string item in Directory.GetFiles(sourceDirName)) { i++; File.Copy(item, destDirName + Path.GetFileName(item), true); FileCopyWork.ReportProgress(i * 100 / count); lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1); lbl_Per.Text = (i * 100 / count + "%"); Thread.Sleep(100); } foreach (string item in Directory.GetDirectories(sourceDirName)) { Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1)); } } } catch (Exception e) { MessageBox.Show(e.Message); } }这个是哪个复制文件的代码,怎么弄啊 或者换个更方便的方法,把版本文件放在最后复制。 private void Copy(string sourceDirName, string destDirName) { try { if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\") { sourceDirName = sourceDirName + "\\"; } if (destDirName.Substring(destDirName.Length - 1) != "\\") { destDirName = destDirName + "\\"; } if (Directory.Exists(sourceDirName)) { if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } string version = "";//改成版本文件名 foreach (string item in Directory.GetFiles(sourceDirName)) { i++; // 增加判断 if (item != version) File.Copy(item, destDirName + Path.GetFileName(item), true); FileCopyWork.ReportProgress(i * 100 / count); lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1); lbl_Per.Text = (i * 100 / count + "%"); Thread.Sleep(100); } foreach (string item in Directory.GetDirectories(sourceDirName)) { Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1)); } //最后复制 File.Copy(version, destDirName + Path.GetFileName(version), true); } } catch (Exception e) { MessageBox.Show(e.Message); } } 谢谢哥哥啊,这个Copy的方法可行吗?那个version的值还是空的,没有给他赋值啊。帮帮忙解答下 你自己改啊,具体哪个版本文件只有你自己知道不是吗……这个代码是我们组长给我的,他就说让我解决这个问题。string version="",怎么给他赋值啊,就是最后更想他的版本号 这个是那个config.xml配置文件<?xml version="1.0" encoding="gb2312"?><Root> <!-- 数据库 相关设置--> <DataBase DataSource="localhost" InitialCatalog="" UserID="" Password="" /> <Server URL="localhost" /> <User userid="admin" ischecked="true" /> <Skin commonskin="Eighteen.ssk" logonskin="Eighteen.ssk" /> <User userid="admin" ischecked="true" /> <App Version="2.5.4" /> <UpdateDocu DocuName="CDMSUpdate" /></Root>我真的不会啊 config.xml不就是你的记录版本的文件吗,把这个最后复制就可以了。string version = @"config.xml";//可能文件名之前还要加上路径,这个你自己判断。 谢谢啦,把那个string version="XXXXX"弄好就可以了吗 private void Copy(string sourceDirName, string destDirName) { try { if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\") { sourceDirName = sourceDirName + "\\"; } if (destDirName.Substring(destDirName.Length - 1) != "\\") { destDirName = destDirName + "\\"; } if (Directory.Exists(sourceDirName)) { if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } string version = Application.StartupPath+ "config.xml";//改成版本文件名 foreach (string item in Directory.GetFiles(sourceDirName)) { i++; // 增加判断 if (item != version) File.Copy(item, destDirName + Path.GetFileName(item), true); FileCopyWork.ReportProgress(i * 100 / count); lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1); lbl_Per.Text = (i * 100 / count + "%"); Thread.Sleep(100); } foreach (string item in Directory.GetDirectories(sourceDirName)) { Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1)); } //最后复制 File.Copy(version, destDirName + Path.GetFileName(version), true); } } catch (Exception e) { MessageBox.Show(e.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } }我试过了,如果我把窗体关闭假造断网的情况他的config.xml文件已经更新了,你这个方法不行啊 关闭后跑到异常处理的地方吗,就是这一句:MessageBox.Show(e.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error);没有的话,说明没有异常,当然会正常复制的。 /// <summary> /// 文件夹复制 /// </summary> /// <param name="sourceDirName">原始路径</param> /// <param name="destDirName">目标路径</param> /// <returns></returns> private void Copy(string sourceDirName, string destDirName) { try { if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\") { sourceDirName = sourceDirName + "\\"; } if (destDirName.Substring(destDirName.Length - 1) != "\\") { destDirName = destDirName + "\\"; } if (Directory.Exists(sourceDirName)) { if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } string version = Application.StartupPath + "\\config.xml"; foreach (string item in Directory.GetFiles(sourceDirName)) { i++; // 增加判断 if (item != version) File.Copy(item, destDirName + Path.GetFileName(item), true); FileCopyWork.ReportProgress(i * 100 / count); lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1); lbl_Per.Text = (i * 100 / count + "%"); Thread.Sleep(100); } foreach (string item in Directory.GetDirectories(sourceDirName)) { Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1)); } //最后复制 File.Copy(version, destDirName + Path.GetFileName(version), true); } } catch (Exception e) { MessageBox.Show(e.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } }这个判断 if (item != version),我调试过了,这2个路径根本不可能一样,所以这个判断没用,item是源目标,version是目标 C#中用Graphic绘制的图片,如何显示图片的鼠标提示 WinForm中App.config数据库连接问题 SQL Update select C#WinForm中如何实现窗体的动态加载 必须声明变量 '@pp'...求救!! 我用到CSS 3.0,如何设置使C#不提示错误? C#代碼輸出疑惑 谁有关于C#下做P2P技术的资料,急,在线等 请教怎么样读写XML文件? 刚开始学,有个问题一直搞不懂,请各位大神帮帮忙 C# 线程 和 委托的使用 今天看见一个之前没见过的方法写法(看看有没有大牛知道)
private void Copy(string sourceDirName, string destDirName)
{
try
{
if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\")
{
sourceDirName = sourceDirName + "\\";
}
if (destDirName.Substring(destDirName.Length - 1) != "\\")
{
destDirName = destDirName + "\\";
}
if (Directory.Exists(sourceDirName))
{
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
foreach (string item in Directory.GetFiles(sourceDirName))
{
i++;
File.Copy(item, destDirName + Path.GetFileName(item), true);
FileCopyWork.ReportProgress(i * 100 / count);
lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1);
lbl_Per.Text = (i * 100 / count + "%");
Thread.Sleep(100);
}
foreach (string item in Directory.GetDirectories(sourceDirName))
{
Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1));
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
这个是哪个复制文件的代码,怎么弄啊
{
try
{
if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\")
{
sourceDirName = sourceDirName + "\\";
}
if (destDirName.Substring(destDirName.Length - 1) != "\\")
{
destDirName = destDirName + "\\";
}
if (Directory.Exists(sourceDirName))
{
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
string version = "";//改成版本文件名
foreach (string item in Directory.GetFiles(sourceDirName))
{
i++;
// 增加判断
if (item != version)
File.Copy(item, destDirName + Path.GetFileName(item), true);
FileCopyWork.ReportProgress(i * 100 / count);
lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1);
lbl_Per.Text = (i * 100 / count + "%");
Thread.Sleep(100);
}
foreach (string item in Directory.GetDirectories(sourceDirName))
{
Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1));
}
//最后复制
File.Copy(version, destDirName + Path.GetFileName(version), true);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
你自己改啊,具体哪个版本文件只有你自己知道不是吗……
这个代码是我们组长给我的,他就说让我解决这个问题。string version="",怎么给他赋值啊,就是最后更想他的版本号
<?xml version="1.0" encoding="gb2312"?>
<Root>
<!-- 数据库 相关设置-->
<DataBase DataSource="localhost" InitialCatalog="" UserID="" Password="" />
<Server URL="localhost" />
<User userid="admin" ischecked="true" />
<Skin commonskin="Eighteen.ssk" logonskin="Eighteen.ssk" />
<User userid="admin" ischecked="true" />
<App Version="2.5.4" />
<UpdateDocu DocuName="CDMSUpdate" />
</Root>
我真的不会啊
config.xml不就是你的记录版本的文件吗,把这个最后复制就可以了。
string version = @"config.xml";//可能文件名之前还要加上路径,这个你自己判断。
{
try
{
if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\")
{
sourceDirName = sourceDirName + "\\";
}
if (destDirName.Substring(destDirName.Length - 1) != "\\")
{
destDirName = destDirName + "\\";
}
if (Directory.Exists(sourceDirName))
{
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
string version = Application.StartupPath+ "config.xml";//改成版本文件名
foreach (string item in Directory.GetFiles(sourceDirName))
{
i++;
// 增加判断
if (item != version)
File.Copy(item, destDirName + Path.GetFileName(item), true);
FileCopyWork.ReportProgress(i * 100 / count);
lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1);
lbl_Per.Text = (i * 100 / count + "%");
Thread.Sleep(100);
}
foreach (string item in Directory.GetDirectories(sourceDirName))
{
Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1));
}
//最后复制
File.Copy(version, destDirName + Path.GetFileName(version), true);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
我试过了,如果我把窗体关闭假造断网的情况他的config.xml文件已经更新了,你这个方法不行啊
MessageBox.Show(e.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error);没有的话,说明没有异常,当然会正常复制的。
/// 文件夹复制
/// </summary>
/// <param name="sourceDirName">原始路径</param>
/// <param name="destDirName">目标路径</param>
/// <returns></returns> private void Copy(string sourceDirName, string destDirName)
{
try
{
if (sourceDirName.Substring(sourceDirName.Length - 1) != "\\")
{
sourceDirName = sourceDirName + "\\";
}
if (destDirName.Substring(destDirName.Length - 1) != "\\")
{
destDirName = destDirName + "\\";
}
if (Directory.Exists(sourceDirName))
{
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
string version = Application.StartupPath + "\\config.xml";
foreach (string item in Directory.GetFiles(sourceDirName))
{
i++;
// 增加判断
if (item != version)
File.Copy(item, destDirName + Path.GetFileName(item), true);
FileCopyWork.ReportProgress(i * 100 / count);
lbl_Docu.Text = item.Substring(item.LastIndexOf('\\') + 1);
lbl_Per.Text = (i * 100 / count + "%");
Thread.Sleep(100);
}
foreach (string item in Directory.GetDirectories(sourceDirName))
{
Copy(item, destDirName + item.Substring(item.LastIndexOf("\\") + 1));
}
//最后复制
File.Copy(version, destDirName + Path.GetFileName(version), true);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "更新失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
这个判断 if (item != version),我调试过了,这2个路径根本不可能一样,所以这个判断没用,item是源目标,version是目标