[英]'string' does not contain a definition for/
Error : 'string' does not contain a definition for 'SelectedPath' and no extension method 'SelectedPath' accepting a first argument of type 'string' could be found 错误 :“字符串”不包含“ SelectedPath”的定义,找不到任何接受“字符串”类型的第一个参数的扩展方法“ SelectedPath”
Code : 代码 :
private static string fbd = String.Empty;
public void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select a Folder to save the images.";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
textBox1.Text = fbd.SelectedPath;
}
public void button3_Click(object sender, EventArgs e)
{
List<string> address = new List<string>();
Random r = new Random();
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600000_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600001_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600002_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600003_460s.jpg");
//MessageBox.Show(address[r.Next(0, 4)]);
if (comboBox1.Text == "10")
{
string filename = fbd.SelectedPath;
MessageBox.Show(fbd);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(address[r.Next(0, 4)]));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((response.StatusCode == HttpStatusCode.OK ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.Redirect) &&
response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
{
using (Stream inputStream = response.GetResponseStream())
using (Stream outputStream = File.OpenWrite(filename))
{
byte[] buffer = new byte[4096];
int bytesRead;
do
{
bytesRead = inputStream.Read(buffer, 0, buffer.Length);
outputStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
using (WebClient client = new WebClient())
{
client.DownloadFile(address[r.Next(0, 25)], filename);
}
}
}
}
}
Explanation : For button3_Click im trying to get it to call the save location you set to save the image. 说明 :对于button3_Click,即时消息试图使其调用您设置为保存图像的保存位置。 I have looked all over the net and im not finding a way to fix this :/ 我在网上四处张望,即时通讯找不到解决此问题的方法:/
I also am getting an error when i manually enter a save location. 手动输入保存位置时,也会出现错误。 Access to the path 'H:\\images' is denied. 拒绝访问路径“ H:\\ images”。 And no the folder is not read only. 并且没有文件夹不是只读的。 It gives me the same error no matter where i set the save location. 无论我在哪里保存位置,它都会给我同样的错误。
fdb is a string. fdb是一个字符串。 You have declared a class-wide field called fdb of type string, which doesn't have the property SelectedPath 您已经声明了一个名为字符串类型fdb的类范围的字段,它没有属性SelectedPath
In yout button2_click method, you have a File Dialog that presumably you want to access instead, so you need to declare that in the class-wide scope instead. 在button2_click方法中,您有一个文件对话框,可能您想访问它,因此您需要在类范围的范围内声明它。
private FolderBrowserDialog _fbDlg;
private static string fbd = String.Empty; // Do you really need this?
public void button2_Click(object sender, EventArgs e)
{
_fbDlg = new FolderBrowserDialog();
_fbDlg.Description = "Select a Folder to save the images.";
if (_fbDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
textBox1.Text = _fbDlg.SelectedPath;
}
public void button3_Click(object sender, EventArgs e)
{
List<string> address = new List<string>();
Random r = new Random();
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600000_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600001_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600002_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600003_460s.jpg");
//MessageBox.Show(address[r.Next(0, 4)]);
if (comboBox1.Text == "10")
{
string filename = _fbDlg.SelectedPath;
The problem is that you have declared two variables with the same name - fbd
: 问题是您已经声明了两个具有相同名称的变量fbd
:
private static string fbd = String.Empty;
FolderBrowserDialog fbd = new FolderBrowserDialog();
Rename one of them to avoid confusion. 重命名其中之一以避免混淆。 Then I think you will be able to figure out the correct solution to your problem. 然后,我认为您将能够找到解决问题的正确方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.