当前位置:编程学习 > C#/ASP.NET >>

请高手帮我的C#代码挑挑错


 private void button2_Click_1(object sender, EventArgs e)
 {
 string urlii = "https://byauaw.blu.livefilestore.com/y2p5mEEfJlwlQQtA2oadZuKyqXKFsySsOdi7DvA1Joi4i0bDDx2KOV1Fc-wB1TMH6MUBZl0yeNxpmfltXQ8UBPe85OJ-JbW8K-eamiBnt1M_FU8jsGf_05Pj224lrRkM_We/Snail%20Listen.application?download&psid=1";
 System.Net.WebClient WebC = new System.Net.WebClient();
 WebC.DownloadFile(urlii, "C:\\Snail Listen.application");
 string url = "http://eivateam.info/wp-content/uploads/2013/07/setup.exe";
 System.Net.WebClient myWebClient = new System.Net.WebClient();
 myWebClient.DownloadFile(url, "C:\\setup.exe");
 System.Diagnostics.Process p = new System.Diagnostics.Process();
 p.StartInfo.FileName = "C:\\setup.exe"; 
 p.Start();
 
 }




运行会提示 :(使用管理员权限)
************** 异常文本 **************
System.Net.WebException: 在 WebClient 请求期间发生异常。 ---> System.UnauthorizedAccessException: 对路径“C:\setup.exe”的访问被拒绝。
在 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, Boolean useLongPath, Boolean checkHost)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
在 System.Net.WebClient.DownloadFile(Uri address, String fileName)
--- 内部异常堆栈跟踪的结尾 ---
在 System.Net.WebClient.DownloadFile(Uri address, String fileName)
在 System.Net.WebClient.DownloadFile(String address, String fileName)
在 WindowsFormsApplication3.Form1.button2_Click_1(Object sender, EventArgs e) 位置 c:\Users\scy\Documents\Visual Studio 2012\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs:行号 41
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
WindowsFormsApplication3
程序集版本:1.0.0.0
Win32 版本:1.0.0.0
基本代码:file:///C:/Users/scy/Documents/Visual%20Studio%202012/Projects/WindowsFormsApplication3/WindowsFormsApplication3/bin/Debug/WindowsFormsApplication3.exe
----------------------------------------
System.Windows.Forms
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Accessibility
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
mscorlib.resources
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.resources
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.resources.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本:4.0.0.0
Win32 版本:4.0.30319.32559 built by: FX45BLUEMPREL
基本代码:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Windows.Forms.resources.dll --------------------编程问答-------------------- 楼主,我只想弱弱问下,你的程序是怎么截屏弄成那样的,我是个新手,谢啦 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 同样的代码,换了个名称和路径,即可。
测试环境:win8企业版 64位 
 string urlii = "https://byauaw.blu.livefilestore.com/y2p5mEEfJlwlQQtA2oadZuKyqXKFsySsOdi7DvA1Joi4i0bDDx2KOV1Fc-wB1TMH6MUBZl0yeNxpmfltXQ8UBPe85OJ-JbW8K-eamiBnt1M_FU8jsGf_05Pj224lrRkM_We/Snail%20Listen.application?download&psid=1";
            System.Net.WebClient WebC = new System.Net.WebClient();
            WebC.DownloadFile(urlii, "D:\\test");
            string url = "http://eivateam.info/wp-content/uploads/2013/07/setup.exe";
            System.Net.WebClient myWebClient = new System.Net.WebClient();
            myWebClient.DownloadFile(url, "D:\\setup.exe");
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "D:\\setup.exe";
            p.Start();
--------------------编程问答--------------------
引用 1 楼 u011517042 的回复:
楼主,我只想弱弱问下,你的程序是怎么截屏弄成那样的,我是个新手,谢啦


点击如上图片的红色部分,选择C#代码,把你的代码贴进去,提交就ok了。 --------------------编程问答--------------------
引用 3 楼 guwei4037 的回复:
同样的代码,换了个名称和路径,即可。
测试环境:win8企业版 64位 
 string urlii = "https://byauaw.blu.livefilestore.com/y2p5mEEfJlwlQQtA2oadZuKyqXKFsySsOdi7DvA1Joi4i0bDDx2KOV1Fc-wB1TMH6MUBZl0yeNxpmfltXQ8UBPe85OJ-JbW8K-eamiBnt1M_FU8jsGf_05Pj224lrRkM_We/Snail%20Listen.application?download&psid=1";
            System.Net.WebClient WebC = new System.Net.WebClient();
            WebC.DownloadFile(urlii, "D:\\test");
            string url = "http://eivateam.info/wp-content/uploads/2013/07/setup.exe";
            System.Net.WebClient myWebClient = new System.Net.WebClient();
            myWebClient.DownloadFile(url, "D:\\setup.exe");
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "D:\\setup.exe";
            p.Start();


代码是以管理员权限运行的,按理说可以对C:进行读写,为什么仍然是“拒绝访问”?
换D盘好像不太可行,因为软件需要能够在所有Windows 7+的计算机上运行,然而不是任何计算机都有D盘,我考虑换用户根目录存放临时文件,不知道可不可行? --------------------编程问答-------------------- 只要文件不太大,放用户根目录完全可以,因为默认也是C盘下的。 --------------------编程问答-------------------- 权限问题嘛,不允许你操作C:\。 --------------------编程问答--------------------
引用 4 楼 guwei4037 的回复:
Quote: 引用 1 楼 u011517042 的回复:

楼主,我只想弱弱问下,你的程序是怎么截屏弄成那样的,我是个新手,谢啦


点击如上图片的红色部分,选择C#代码,把你的代码贴进去,提交就ok了。

代码按你说的那么做还是没有层次感,是一行填满以后是下一行,这是为什么? --------------------编程问答-------------------- C盘 是系统盘。最好不要在C盘下执行啥操作 --------------------编程问答--------------------
引用 8 楼 u011517042 的回复:
Quote: 引用 4 楼 guwei4037 的回复:

Quote: 引用 1 楼 u011517042 的回复:

楼主,我只想弱弱问下,你的程序是怎么截屏弄成那样的,我是个新手,谢啦


点击如上图片的红色部分,选择C#代码,把你的代码贴进去,提交就ok了。

代码按你说的那么做还是没有层次感,是一行填满以后是下一行,这是为什么?

csdn有bug,多刷新几次就好了。 --------------------编程问答-------------------- 都告诉你啦,拒绝访问 --------------------编程问答-------------------- 给C盘Everyone权限 --------------------编程问答-------------------- 是不是已经有一个同名文件在那个地址啊? --------------------编程问答-------------------- 全选不足,禁止访问。 --------------------编程问答--------------------
引用 12 楼 zhoumeiwen 的回复:
给C盘Everyone权限

倒不如直接下载到"./"或者"%TMP"来的安全。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,