Search code examples
svgrazordotnetnuke2sxc

Is there a way to have the user upload an SVG file but then render the SVG source?


Using 2sxc on DNN, I have a website that uses SVGs for icons in content types. The client wants to be able to upload the SVG icons to 2sxc via a Link field but then instead of rendering <img src="@Content.SVG" />, they want it to render the source code of the SVG (so we could manipulate the fill color via CSS). Is this even possible and how could it be done?


Solution

  • Basically 2 steps

    1. Get the real file name using 2sxc and DNN
    2. Then load the file as a string using normal .net stuff System.IO and add it to your html - https://learn.microsoft.com/en-us/dotnet/api/system.io.file.readalltext?view=netframework-4.5.1

    ca. like this

    <div>
     @Html.Raw(System.IO.File.ReadAllText(fileName)
    </div>