views:

19

answers:

2

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";
+1  A: 

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

Don Kirkby
+2  A: 

You should be able to use

Path.GetFileName

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

astander
Ah ok cool. But where exactly do I edit the data I grab from my table? At the end of my SQL statement ------- select new { Path.GetFileName(c.Location), c.ID }; That doesn't work
Justen
Show some code so we can have a look at what you are doing.
astander
I've figured it out, update in OP. Thanks for the Path.GetFileName()
Justen