question

Benjoe-2576 avatar image
0 Votes"
Benjoe-2576 asked Benjoe-2576 answered

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

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-graph-mail
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It's not a Graph issue, rather how the value is passed wrongly to it. I see that you're already using Linq then you can use REGEX to get the info; check out the related thread and you may need to tweak as your requirement.


0 Votes 0 ·

1 Answer

Benjoe-2576 avatar image
0 Votes"
Benjoe-2576 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.