未处理 System.UnauthorizedAccessException
Message="对路径“C:\\Documents and Settings\\All Users\\temp\\app”的访问被拒绝。"
Source="mscorlib"
StackTrace:
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
在 AutoUpdate.FrmUpdate.DownUpdateFile() 位置 D:\Temp\AutoUpdate\AutoUpdate\FrmUpdate.cs:行号 508
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
Message="对路径“C:\\Documents and Settings\\All Users\\temp\\app”的访问被拒绝。"
Source="mscorlib"
StackTrace:
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
在 AutoUpdate.FrmUpdate.DownUpdateFile() 位置 D:\Temp\AutoUpdate\AutoUpdate\FrmUpdate.cs:行号 508
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
解决方案 »
- 求救:获取网站页面信息,当保存内容时出错了“调用的目标发生了异常”,怎么办?
- 流媒体安全方面的问题
- C#中,我在子窗体中查询出来的数据,如何填充到父窗体的DataGridView中去?
- VS2005 中GridView如何实现主从表的新增修改,谢谢
- office 2次开发的问题
- 突然发现VS2005 的 devenv.exe 是在 Common7 目录下
- 如何 获取远程计算机的进程啊>(没分了,不好意思啊)
- 关于C#通过程序实现在虚拟目录中创建文件夹(a problem about Directory Creation)
- C#添加了ADOX,应该怎样连接?
- ListView 中的Column 如何才能显示出来啊?
- .net2005 c#中如何将数值型转换成字符型
- C#中关于自定义控件变为容器的问题?
Message="未能找到路径“C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\_ItemSoft_y_x_m_\\”的一部分。"
Source="mscorlib"
StackTrace:
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
在 AutoUpdate.FrmUpdate.DownUpdateFile() 位置 D:\Temp\AutoUpdate\AutoUpdate\FrmUpdate.cs:行号 508
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
应该是这个.前面的我测试时候修改了下
这是出错的语句. tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\"+ "_"+ updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value+"_"+"y"+"_"+"x"+"_"+"m"+"_"+"\\";
string tempPath = tempUpdatePath; 这是tempPath 的定义
private string tempUpdatePath = string.Empty;
XmlFiles updaterXmlFiles = null;
private int availableUpdate = 0;
bool isRun = false;
string mainAppExe = ""; /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FrmUpdate());
} private void FrmUpdate_Load(object sender, System.EventArgs e)
{
panel2.Visible = false;
btnFinish.Visible = false; string localXmlFile = Application.StartupPath + "\\UpdateList.xml";
string serverXmlFile = string.Empty;
try
{
//从本地读取更新配置文件信息
updaterXmlFiles = new XmlFiles(localXmlFile );
}
catch
{
MessageBox.Show("配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.Close();
return;
}
//获取服务器地址
updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater();
appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件
try
{
//tempUpdatePath = "C:\\Documents and Settings\\All Users\\temp\\app";
tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\"+ "_"+ updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value+"_"+"y"+"_"+"x"+"_"+"m"+"_"+"\\";
appUpdater.DownAutoUpdateFile(tempUpdatePath);
}
catch
{
MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
return; } //获取更新文件列表
Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml";
if(!File.Exists(serverXmlFile))
{
return;
} availableUpdate = appUpdater.CheckForUpdate(serverXmlFile,localXmlFile,out htUpdateFile);
if (availableUpdate > 0)
{
for(int i=0;i<htUpdateFile.Count;i++)
{
string [] fileArray =(string []) htUpdateFile[i];
lvUpdateList.Items.Add(new ListViewItem(fileArray));
}
}
else
btnNext.Enabled = false;
} private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
Application.ExitThread();
Application.Exit();
} private void btnNext_Click(object sender, System.EventArgs e)
{
if (availableUpdate > 0)
{
Thread threadDown=new Thread(new ThreadStart(DownUpdateFile));
threadDown.IsBackground = true;
threadDown.Start();
}
else
{
MessageBox.Show("没有可用的更新!","自动更新",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
} } private void Invokefun()
{
this.Cursor = Cursors.WaitCursor;
} private void ThreadFun()
{
MethodInvoker mi = new MethodInvoker(this.Invokefun);
this.BeginInvoke(mi);
}
private void DownUpdateFile()
{ Thread thdProcess = new Thread(new ThreadStart(ThreadFun));
thdProcess.Start(); //Thread thpress = new Thread(new ThreadStart(Thrun));
//thpress.Start();
mainAppExe = updaterXmlFiles.GetNodeValue("//EntryPoint");
Process[] allProcess = Process.GetProcesses();
foreach (Process p in allProcess)
{ if (p.ProcessName.ToLower() + ".exe" == mainAppExe.ToLower())
{
for (int i = 0; i < p.Threads.Count; i++)
p.Threads[i].Dispose();
p.Kill();
isRun = true;
//break;
}
}
WebClient wcClient = new WebClient();
for (int i = 0; i < this.lvUpdateList.Items.Count; i++)
{
string UpdateFile = lvUpdateList.Items[i].Text.Trim();
string updateFileUrl = updateUrl + lvUpdateList.Items[i].Text.Trim();
long fileLength = 0; WebRequest webReq = WebRequest.Create(updateFileUrl);
WebResponse webRes = webReq.GetResponse();
fileLength = webRes.ContentLength; lbState.Text = "正在下载更新文件,请稍后...";
pbDownFile.Value = 0;
pbDownFile.Maximum = (int)fileLength; try
{
Stream srm = webRes.GetResponseStream();
StreamReader srmReader = new StreamReader(srm);
byte[] bufferbyte = new byte[fileLength];
int allByte = (int)bufferbyte.Length;
int startByte = 0;
while (fileLength > 0)
{
Application.DoEvents();
int downByte = srm.Read(bufferbyte, startByte, allByte);
if (downByte == 0) { break; };
startByte += downByte;
allByte -= downByte;
pbDownFile.Value += downByte; float part = (float)startByte / 1024;
float total = (float)bufferbyte.Length / 1024;
int percent = Convert.ToInt32((part / total) * 100); this.lvUpdateList.Items[i].SubItems[2].Text = percent.ToString() + "%"; } string tempPath = tempUpdatePath; //UpdateFile;
CreateDirtory(tempPath);
FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(bufferbyte, 0, bufferbyte.Length);
srm.Close();
srmReader.Close();
fs.Close();
}
catch (WebException ex)
{
MessageBox.Show("更新文件下载失败!" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
InvalidateControl();
this.Cursor = Cursors.Default;
}
//创建目录
private void CreateDirtory(string path)
{
if(!File.Exists(path))
{
string [] dirArray = path.Split('\\');
string temp = string.Empty;
for(int i = 0;i<dirArray.Length - 1;i++)
{
temp += dirArray[i].Trim() + "\\";
if(!Directory.Exists(temp))
Directory.CreateDirectory(temp);
}
}
} //复制文件;
public void CopyFile(string sourcePath,string objPath)
{
// char[] split = @"\".ToCharArray();
if(!Directory.Exists(objPath))
{
Directory.CreateDirectory(objPath);
}
string[] files = Directory.GetFiles(sourcePath);
for(int i=0;i<files.Length;i++)
{
string[] childfile = files[i].Split('\\');
File.Copy(files[i],objPath + @"\" + childfile[childfile.Length-1],true);
}
string[] dirs = Directory.GetDirectories(sourcePath);
for(int i=0;i<dirs.Length;i++)
{
string[] childdir = dirs[i].Split('\\');
CopyFile(dirs[i],objPath + @"\" + childdir[childdir.Length-1]);
}
} private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
//打开网页
System.Diagnostics.Process.Start(linkLabel1.Text);
}
//点击完成复制更新文件到应用程序目录
private void btnFinish_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
try
{
CopyFile(tempUpdatePath,Directory.GetCurrentDirectory());
System.IO.Directory.Delete(tempUpdatePath,true);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
if(true == this.isRun) Process.Start(mainAppExe);
}
private void InvalidateControl()
{
panel2.Location = panel1.Location;
panel2.Size = panel1.Size;
panel1.Visible = false;
panel2.Visible = true; btnNext.Visible = false;
btnCancel.Visible = false;
btnFinish.Location = btnCancel.Location;
btnFinish.Visible = true;
}
//判断主应用程序是否正在运行
private bool IsMainAppRun()
{
string mainAppExe = updaterXmlFiles.GetNodeValue("//EntryPoint");
bool isRun = false;
Process [] allProcess = Process.GetProcesses();
foreach(Process p in allProcess)
{
if (p.ProcessName.ToLower() + ".exe" == mainAppExe.ToLower() )
{
isRun = true;
//break;
}
}
return isRun;
}
}
}
{
System.IO.Directory.CreateDirectory(tempUpdatePath);
}appUpdater.DownAutoUpdateFile(tempUpdatePath);
Message="未能找到路径“C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\_ItemSoft_y_x_m_\\”的一部分。"
Source="mscorlib"
StackTrace:
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
在 AutoUpdate.FrmUpdate.DownUpdateFile() 位置 D:\Temp\AutoUpdate\AutoUpdate\FrmUpdate.cs:行号 511
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
出现这个问题了...
C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\
没有权限 要不改成在你项目里建一个Temp文件,
在你的项目文件夹里的Temp创建这个文件夹_ItemSoft_y_x_m_
Message="对路径“D:\\Temp\\AutoUpdate\\AutoUpdate\\temp\\_ItemSoft_y_x_m_”的访问被拒绝。"
Source="mscorlib"
StackTrace:
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
在 AutoUpdate.FrmUpdate.DownUpdateFile() 位置 D:\Temp\AutoUpdate\AutoUpdate\FrmUpdate.cs:行号 511
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()]\
照楼上的方法出现这个错误..
文件夹_ItemSoft_y_x_m_属性还是只读,不能更改