0

i am looking to write an image into doc file ..

here is the code that i am trying...

string imageFolder = System.Web.Configuration.WebConfigurationManager.AppSettings["coverLetterPath"].ToString();
string imageName = "images.jpg";
string path1 = Path.Combine(imageFolder, imageName);
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path1))
{
    sw.WriteLineAsync(imageName);
}
string fileName = string.Empty;
fileName = "BodyContent_" + DateTime.Now.ToString("ddMMMyyy_HHmmss_fff") + ".docx";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.TransmitFile(path1);
Response.Flush();
Response.End();

here the file that i am creating is downloaded but the image is not loaded into that file.. getting a message when i open the doc as File is corrupted

thiru
  • 173
  • 1
  • 4
  • 16
  • it's just a guess here but try converting it to a byte[] and add that to the file, see if that works.. – Spluf Apr 26 '16 at 12:37
  • 1
    Possible duplicate of [How to write an image from byte\[\] into MS WORD using C# Windows application](http://stackoverflow.com/questions/26567042/how-to-write-an-image-from-byte-into-ms-word-using-c-sharp-windows-application) – fruggiero Apr 26 '16 at 12:37
  • 1
    Saving a .jpg file with a .docx extension does not make it a word document – user469104 Apr 26 '16 at 13:21

0 Answers0