Attach an Image stored in a Sql server table and a folder in my application using MailMessage C#

Benjoe 431 Reputation points
2021-06-30T03:21:28.833+00:00

I am using MVC5 aspplication and storing an image in both sql server table and a folder in my application and I want to add the image as an attachment to an email to users using MailMessage class. My image source looks like this:

"<p><img src=\"/postedImage/baby220210629224910.jpg\"><br></p>"

from my Linq query

public ActionResult NewsEvents(PostVM entity )
{

        var dbnew = new Post();
        dbnew.newsId = entity.newsId;           
        dbnew.Content = entity.Content;

using (var mail = new MailMessage())
{
mail.Attachments.Add(new Attachment(dbnew.Content)); dbnew.Content --->"<p><img src=\"/postedImage/baby220210629224910.jpg\"><br></p>"

}

I get an error "Illegal characters in path."
How do I get only "baby220210629224910.jpg" from the path above

Microsoft Security Microsoft Graph
{count} votes

Accepted answer
  1. Benjoe 431 Reputation points
    2021-07-05T16:29:34.793+00:00

    After much struggle, I have been able to get it working correctly with a help from codeproject. I am attaching the link here to help anybody and also give the guy who helped me credit

    https://www.codeproject.com/Answers/5307164/How-to-retrieve-an-image-stored-in-the-SQL-server#answer2

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.