I’m using an UpdatePanel in ASP.Net WebForms to upload a image. I set the Image.ImageUrl to the full virtual path to the image (/images/news/filenname.jpg), but I only want to save the filename in the database (filename.jpg). How do I customize the SqlDataSource to only take part of the URL?
<asp:SqlDataSource
ID="SqlDataSourceNews"
runat="server"
ConnectionString="<%$ ConnectionStrings:connectionString %>"
UpdateCommand="UPDATE [foo] SET [pic] = @pic WHERE [id] = @id">
<UpdateParameters>
<asp:Parameter Name="pic" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="pic" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
You can set the update parameters on page_load and use substring function to get only file name from full url: