Error : 'string' does not contain a definition for 'SelectedPath' and no extension method 'SelectedPath' accepting a first argument of type 'string' could be found
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. 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. 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. You have declared a class-wide field called fdb of type string, which doesn't have the property 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.
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
:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.