0

My image name is; "1#34DEMO34#13012020#151037.jpg"

The image name automatically creates from the camera.

1 = CameraID

34DEMO34 = Plate

13012020 = ddMMyyyy

151037 = HHmmss

I test it;

    <div style="bacground-image: url(1#34DEMO34#13012020#151037.jpg) width:200px; heig...." ></div>
    <image src="1#34DEMO34#13012020#151037.jpg" /> 
    <asp:Image ImageUrl="1#34DEMO34#13012020#151037.jpg" />

The name have 3 '#' character. If I change one '#' to '_' is work.

But I can't change it because another application use this images.

How can I show this images on my page ?

VolkanCetinkaya
  • 645
  • 7
  • 13
  • The `#` is a fragment identifier when included in a URL. You should rename the file to something that doesn't contain the fragment identifier. Probably best to assign a unique ID to each file (such as a [GUID](https://learn.microsoft.com/en-us/dotnet/api/system.guid.newguid?view=netframework-4.8)), and rename the file to include the unique identifier. You can store the other characteristics of the file (the Camera ID, plate, date, etc) in your database associated with that ID. – mason Jan 30 '20 at 18:32
  • I cant rename it because another application use this images. – VolkanCetinkaya Jan 30 '20 at 18:35
  • 1
    Well then that other application is just going to have to be adjusted. [Fragment identifiers aren't even sent to the server](https://stackoverflow.com/questions/14462218/is-the-url-fragment-identifier-sent-to-the-server). You *might* be able to URL encode the hash (replace the `#` with `%23`) but using external file names that aren't web compatible is something you should really change. – mason Jan 30 '20 at 18:40

1 Answers1

1

Use Server.UrlEncode to encode special characters.

<asp:Image id="imgTest" />

In code behind, set ImageUrl property.

imgTest.ImageUrl=Server.UrlEncode("1#34DEMO34#13012020#151037.jpg");

Note that this will also encode \. So if you have '\' in your path, only use UrlEncode on filename and not whole path.

Sailesh Babu Doppalapudi
  • 1,534
  • 1
  • 10
  • 22