Posts
349
Comments
106
Trackbacks
4
Bilderpfad in web.config / appSettings

Damit ich mir das nicht mehr raussuchen hier eine Anleitung wie man eine Bilderpfad in der web.config speichert und in den ImageUrl-Parameter eines aspx:image-Tags einfügt:

Eintrag in der web.config:

<configuration>
 <appSettings >
    <addkey="ImagePath"value="~/Images/" />
 </appSettings>
</configuration>


Eine allgemeine Methode zu auslesen der appSettings:

public static string GetAppSettings(string keyname)
{
    string keyVal = ConfigurationManager.AppSettings.Get(keyname);
    if (keyVal == null)
       throw new System.Exception("AppSettings key '" + keyname + "' not exist.");
 
   return keyVal;
}


Pfad in das aspx:image-Tag einfügen:

<asp:Image ID="Image2" runat="server" Width="120px" Height="130px"
    ImageUrl='<%# this.GetImagePath(Eval("Bild")) %>' />

 
Die Methode “GetImagePath” in der codebehind-Datei:

protected string GetImagePath(object picture)
{
   return Utils.GetAppSettings("ImagePath",true) + picture;
}
posted on Wednesday, January 06, 2010 3:22 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 6 and 4 and type the answer here: