Search code examples
dotnetnuke2sxc

How can I rename files uploaded through ADAM in 2SXC?


Using the 2SXC Content module, I have a simple Hero content type and template that includes a title and a background image. I use a C# Razor template and when my users upload a background image via ADAM, the razor template applies the background through inline CSS. Something like this:

@if (Content.BackgroundImage != "") {
   <style type="text/css">
    section.hero {
     background-image: url(@Content.BackgroundImage);
   }
}

The problem is that if the user uploads a file name that has spaces and/or illegal characters, the background image will not appear because the browser doesn't like spaces in the filenames in the inline CSS.

How can I make it so that the file uploaded by ADAM strips out the spaces and removes the illegal characters?


Solution

  • @HttpUtility.UrlEncode(Content.BackgroundImage).Replace("+", "%20").Replace("%2f","/")
    

    Using iJungleBoy's suggestion, I used HttpUtility.URLEncode. But it replaced the spaces with +, and / with %2f, so I use .Replace to swap out + for %20 and %f for / to make a nice simple URL. This now accepts images with spaces in it.