拒绝访问路径"C:\ Users \ xxx \ Desktop"

编程入门 行业动态 更新时间:2024-10-27 20:38:17
本文介绍了拒绝访问路径"C:\ Users \ xxx \ Desktop"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经彻底搜索了整个访问被拒绝的问题,在我自己的系统上没有找到与访问Windows窗体有关的任何问题.所有这些问题都与Web应用有关.

I have thoroughly searched the entire access denied questions and did't find any question related to access to windows form on my own system all the questions are related to web app.

public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { byte[] imgdata; FileStream fsrw; string fname; openFileDialog1.Filter = "Sai Files(*.JPG;*.GIF)|*.jpg;*.gif|All files (*.*)|*.*"; openFileDialog1.ShowDialog();//opens the dialog box fname = openFileDialog1.FileName;//stores the file name in fname pictureBox1.ImageLocation = fname;//gives the image location to picturebox fsrw = new FileStream("C:\\Users\\Sainath\\Desktop", FileMode.Open, FileAccess.ReadWrite); imgdata = new byte[fsrw.Length]; fsrw.Read(imgdata, 0, Convert.ToInt32(fsrw.Length)); fsrw.Close(); string s = "insert into imagetest values(@p1,@p2)"; SqlConnection con = new SqlConnection("server=.;Data Source=.;Initial Catalog=Work;Integrated Security=True"); SqlCommand cmd = new SqlCommand(s, con); cmd.Parameters.AddWithValue("@p1", imgdata); cmd.Parameters.AddWithValue("@p2", fname); con.Open(); int i = cmd.ExecuteNonQuery(); con.Close(); Console.WriteLine(i); } }

推荐答案

您可能必须以管理员身份运行程序/IDE才能访问该文件夹.我不确定为什么,但是我遇到了同样的问题.与默认Windows权限有关.让我们知道它是否有效!

You may have to run your program/IDE as Administrator to access that folder. I'm not exactly sure why, but I've had the same problem. Something to do with default Windows permissions. Let us know if it works!

路径指向一个文件夹-而不是文件.我相信基于C语言的FileStreams实际上必须指向文件,而不是目录:即. C:\Users\Username\Desktop\file.extension.您可以尝试一下,让我们知道是否有帮助吗?

The path leads to a folder - not a file. I believe FileStreams in C-based languages must actually point to a file, rather than a directory: ie. C:\Users\Username\Desktop\file.extension . Can you try this and let us know if it helps at all?

更多推荐

拒绝访问路径"C:\ Users \ xxx \ Desktop"

本文发布于:2023-11-08 02:31:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   quot   Users   xxx   Desktop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!