Selected DropDownList and Table Value

IN:

Hi, I have a drop down list and I am getting two errors.

Mistake # 1: My requirement is to select a meeting name from the drop-down list, save it to a string, and use that string later. I want to get the value of a field (which gives me the path where the files are stored) from the database table.

Code:

string selected = DropDownList1.SelectedValue.ToString(); var query = from meet in db.Meets where meet.Summary = selected select meet.Doc_Path; 

I get the error " where meet.Summary=selected " and it says

"cannot implicitly convert a string of type to bool"

Mistake # 2: I want to use the Doc_Path value that I get through the request. I am not sure about the syntax and therefore get an error message when I tried it.

Code:

 string[] dirs = Directory.GetDirectories(query); 

Please, help.

+4
source share
2 answers

Mistake # 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; 

Mistake # 2 - You May Need 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); 
+2
source

Error # 1:

As mentioned earlier, use == instead of = when comparing.

Error # 2:

Why are you using 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 do not 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 the value of meet.Doc_Path not an absolute path, save only the relative path.

0
source

All Articles