文件”正由另一进程使用,因此该进程无法访问此文件。
但是断点调试的时候 总会抱出 文件”XXX“正由另一进程使用,因此该进程无法访问此文件。
多次尝试 无解 请 大侠帮忙
下边上代码
下载页面代码:
updateFlaglbl.Text = "下载成功";
closebtn.Enabled = true;
startbtn.Text = "完成下载";
Process p = new Process();
p.StartInfo.FileName = Application.StartupPath + @"\update.exe";
p.Start();
this.Close();
更新页面代码:
if (File.Exists(Application.StartupPath + @"\update\update.xml"))
{
string version = "";
labelControl1.Text = "正在升级...";
XmlDocument doc = new XmlDocument();
doc.Load(Application.StartupPath + @"\update\update.xml");
XmlNodeList xElement = doc.GetElementsByTagName("files");
XmlNodeList xChild = doc.GetElementsByTagName("file");
version = xElement.Item(0).Attributes["version"].Value.ToString();
string no = xElement.Item(0).Attributes["upgradeno"].Value.ToString();
for (int i = 0; i < int.Parse(xElement.Item(0).Attributes["count"].Value.ToString()); i++)
{
string filename = xChild.Item(i).Attributes["filename"].Value.ToString();
string filepath = xChild.Item(i).Attributes["filepath"].Value.ToString();
if (File.Exists(Application.StartupPath + filepath + filename))
{
if (!Directory.Exists(Application.StartupPath + @"\backup"))
{
Directory.CreateDirectory(Application.StartupPath + @"\backup");
}
File.Copy(Application.StartupPath + filepath + filename, Application.StartupPath + @"\backup\" + filename, true);//复制文件
File.Copy(Application.StartupPath + @"\update\" + filename, Application.StartupPath + filepath + filename, true);//复制文件
File.Delete(Application.StartupPath + @"\update\" + filename);//删除文件
}
else
{
File.Move(Application.StartupPath + @"\update\" + filename, Application.StartupPath + filepath + filename);//移动文件
}
//修改进度条不能走完的bug
// 源码
progressBarControl1.EditValue = int.Parse(progressBarControl1.EditValue.ToString()) + 1;
//progressBarControl1.EditValue = int.Parse(progressBarControl1.EditValue.ToString()) + i * 100;
}
File.Delete(Application.StartupPath + @"\update\update.xml");
labelControl1.Text = "升级成功!";
XmlDocument ac = new XmlDocument();
ac.Load("ChangeEMR.exe.config");
XmlNode node = ac.SelectSingleNode("//appSettings");
XmlElement element = (XmlElement)node.SelectSingleNode("//add[@key='SysVersion']");
element.SetAttribute("value", version);//修改客户端版本号
XmlElement e = (XmlElement)node.SelectSingleNode("//add[@key='UpgradeNO']");
e.SetAttribute("value", no);
ac.Save("ChangeEMR.exe.config");
}
else
{
this.Hide();
MessageBox.Show("此处不是程序入口点!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.Close();
}
相关推荐
C#程序提示“正由另一进程使用,因此该进程无法访问该文件”的解决办法
主要介绍了C#程序提示“正由另一进程使用,因此该进程无法访问该文件”的解决办法,本文通过改写程序代码实现解决这个问题,需要的朋友可以参考下
C#实现读取被进程占用的文件实现方法
主要介绍了C#实现读取被进程占用的文件实现方法,涉及C#进程操作及文件读取的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
文件无法删除的原因分析及建议
很多朋友都遇到电脑上的文件无法删除但是又不知道改怎么办。这篇文章将解决你的烦恼希望可以帮助大家!
IIS “另一个程序正在使用此文件,进程无法访问。”错误提示的解决办法
如何查看哪个程序打开了tcp 80端口呢?使用“开放端口查看软件Active ports”就可以一目了然了。我查看了一下我的机器情况,如图所示: 从图上看出原来Skype打开了Tcp 80端口,原来是这个家伙惹的祸,将其关闭。再重启IIS,一切正常。 如果在IIS启动之后再开Skype,Skype仍能正常使用。说明Skype发现tcp 80端口已打开就不再使用此端口了。看来启动IIS还得有个顺序,那就是先启动IIS再启动Skype。 补充:其实Skype可以通过设置不让其打开80端口的。这样就不用考虑启动顺序的问题了。具体操作是:Skype 菜单”工具”->”选项”->”连接” 项,
Delphi无法运行,提示EditorLineEnds.ttr另一个程序正在使用此文件,进程无法访问
由于微软补丁KB2982791, KB2970228的缘故,导致Delphi8-DelphiXE在不重起系统的情况下无法被重启两次!提示%TEMP%\EditorLineEnds.ttr另一个程序正在使用此文件,进程无法访问.工具为包括所有版本的修复补丁,请根据需要的版本执行补丁!Delphi2007分WIN8版和其它版的支持


