I’m working on a project that involves a SQLite database and a bunch of images. Everything will be put into an external hard drive, and everything is read-only (no CRUD stuff).
The database contains a table for Photos, with one of the columns (named Path) being paths (strings) to the photos. I want to use a Telerik Rotator to show these photos (which is inside a RadWindow which opens after choosing a row in a RadGrid if that helps you any.)
My problem is: the paths need to be changed. Each one starts with H:\, which I need removed, and replaced with ~/ThisFolder/ (which just points to ../ThisFolder). For every other part of the project, using ResolveUrl("~/ThisFolder/" + path.Remove(0, 3)) has worked, but I can’t figure out how to do it here.
I either need to manipulate the data in the Path column after putting the SQLite data into a DataTable or manipulate the Path strings later on before it goes into the asp:Image tag.
Here’s how I’m grabbing the data from the SQLite database and putting it into a DataTable:
public static DataTable dtTable;
public static string connectionString = ConfigurationManager.ConnectionStrings["Entity"].ConnectionString;
public SQLiteConnection SQLiteConnection = new SQLiteConnection(connectionString);
public SQLiteDataAdapter SQLiteDataAdapter = new SQLiteDataAdapter();
public SQLiteCommand SQLiteCommand = new SQLiteCommand();
private void GetDataSource() //called in Page_Load
{
dtTable = new DataTable();
SQLiteConnection.Open();
try
{
string selectQuery = "SELECT ParentTableID, PhotoID, Path FROM tblPhoto";
SQLiteCommand myCommand = new SQLiteCommand(selectQuery, SQLiteConnection);
using (SQLiteDataReader myReader = myCommand.ExecuteReader())
{
dtTable.Load(myReader);
}
RadRotator1.DataSource = dtTable;
}
finally
{
SQLiteConnection.Close();
}
RadRotator1.DataBind();
}
And here’s my asp tag, so far:
<asp:Image ID="Images" runat="server" AlternateText="Images" ImageUrl='<%#Bind("~/ThisFolder/{0}", "Path")%>' />
Though the ImageURL would be ../ThisFolder/H:/yadayada here….
Any help would be much appreciated! Feel free to ask questions if I’m not being clear somewhere.
I would try SQLLite’s replace.
SELECT ParentTableID, PhotoID, replace(Path,'H:\','') as Path FROM tblPhoto