Justen
Justen

Reputation: 4869

How would I parse a filename from a location I grab from a table before it's bound to the dropdownlist?

So in one of my tables, there lies an image file location. I'm grabbing that information to be displayed in an asp:dropdownlist, however, I want just the name of the image to be displayed. How/Where would I parse the filename out of it. Also, is there a built in method for grabbing the filename?

EDIT::

http://msdn.microsoft.com/en-us/library/bb397663.aspx

instead of:

var oData = from c in oDb.CustomerImages
                    where c.CustomerID == CustomerID         &&
                          c.CustomerNumber == CustomerNumber &&
                          c.CategoryID == CategoryID
                    orderby c.ID
                    select new { Path.GetFileName(c.Location), c.ID };

just set it to a variable, and then set you set your dropdownlist.DataTextField = to that variable's name:

solution:

var oData = from c in oDb.CustomerImages
                    where c.CustomerID == CustomerID         &&
                          c.CustomerNumber == CustomerNumber &&
                          c.CategoryID == CategoryID
                    orderby c.ID
                    select new { Location = Path.GetFileName(c.Location), c.ID };

        return oData;

//elsewhere  ...

dropdownlist.DataTextField = "Location";

Upvotes: 0

Views: 63

Answers (2)

Adriaan Stander
Adriaan Stander

Reputation: 166476

You should be able to use

Path.GetFileName

Returns the file name and extension of the specified path string.

Upvotes: 2

Don Kirkby
Don Kirkby

Reputation: 56710

There's a Path class that has lots of useful methods.

Upvotes: 1

Related Questions