Reputation: 725
Q:
Hi,I have a dropdownlist and i get two errors.
Error #1: My requirement is selecting the meeting name from the dropdownlist, saving it into a string and using that string later. I want to get the field value (which gives me the path where the files are stored) from the database table.
The code :
string selected = DropDownList1.SelectedValue.ToString();
var query = from meet in db.Meets
where meet.Summary = selected
select meet.Doc_Path;
I get an error at "where meet.Summary=selected
" and it says
"cannot implicitly convert type string to bool"
Error #2: I wish to use the Doc_Path
value which I get through the query. I am not sure of the syntax and hence getting an error when I tried it.
The code:
string[] dirs = Directory.GetDirectories(query);
Please help.
Upvotes: 4
Views: 1245
Reputation: 11403
Error # 1:
As said before ,you should use ==
instead of =
when making comparison .
Error # 2:
Why you use Directory.GetDirectories(query);
the previous method is used to Get the names of subdirectories (including their paths) in the specified directory.
look here
i think you don't need this method, just use :
string selected = DropDownList1.SelectedValue.ToString();
var query = from meet in db.Meets
where meet.Summary == selected
select meet.Doc_Path;
string dirPath = System.Web.HttpContext.Current.Server.MapPath("~") + query.ToString();
Make sure that the meet.Doc_Path
value is n't the absolute path, store only the relative path.
Upvotes: 0
Reputation: 1269
Error # 1 - I think you need == instead of just =
string selected = DropDownList1.SelectedValue.ToString();
var query = from meet in db.Meets
where meet.Summary == selected
select meet.Doc_Path;
Error #2 - You may need to user Server.MapPath
String FilePath;
FilePath = Server.MapPath(query);
or, to combine them
string selected = DropDownList1.SelectedValue.ToString();
var query = from meet in db.Meets
where meet.Summary == selected
select Server.MapPath(meet.Doc_Path);
string[] dirs = Directory.GetDirectories(query);
Upvotes: 2