Search code examples
.netvb.netsystem.net.mailsystem.net

How do you set ContentDisposition in a LinkedResource?


Is there a way to set the ContentDisposition of a LinkedResource to be inline, ie in the case of an image?

Here's how I am building my LinkedResource right now:

            Dim img As LinkedResource = New LinkedResource(filePath)

            Dim fileType As String = ""
            Dim attName As String = "image" + fileName + "." + fileExt

            If (fileExt = "jpg" Or fileExt = "jpeg") Then
                img.ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg
            ElseIf (fileExt = "gif") Then
                img.ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Gif
            ElseIf (fileExt = "png") Then
                img.ContentType.MediaType = "image/png"
            End If

            img.ContentId = attName
            img.ContentType.Name = attName
            linkedResources.Add(img)

Solution

  • Adapt the code succinctly described in this answer: https://stackoverflow.com/a/11000938

    This appears to be the right approach. Articles describing this in more detail include these: