문제

Adding a jpeg picture to a mail message using

LinkedResource resPic = new LinkedResource(@"path\Pic.jpg", MediaTypeNames.Image.Jpeg); 

works well, but I need to add the picture from the project Properties.Resources.Pic.

How can that be done ?

도움이 되었습니까?

해결책

One approach would be to save it to disk first:

var fileName = Guid.NewGuid.ToString();
var path = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)),
    fileName);
File.WriteAllBytes(path, Properties.Resources.Pic);

LinkedResource resPic = new LinkedResource(path, MediaTypeNames.Image.Jpeg);

and then when you're done with the whole process, clean up the file:

File.Delete(path);

I'm not guaranteeing that you'll be able to cleanup the file in the same method, so path may need to be a more accessible variable, but you can work out those details.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top