Click here to Skip to main content
14,883,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to save to word doucument but the site just keep loading and when i go to were i save the document the document is created but has no data in it , and i cannot opet it, what could i have misst?


C#
private void SetWordDocument()
        {
            object strFileName =
                 CleanUp(LabelFirstName.Text + "_" + LabelLastName.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd") +
                         "." + DropDownListDownloadCv0.SelectedItem.Text);
           
                    object fileStream =
                new FileStream(Server.MapPath("~/Upload/") +
               strFileName,FileMode.Create);
            
            
            using (var db = new knowitCVdbEntities())
            {
                var theEmpl = (from p in db.EMPLOYEES
                               where p.username == strUserName
                               select p).FirstOrDefault();



                if (theEmpl != null)
            {

                object missing = Missing.Value;
                object start1 = 0;

                var wordApp = new ApplicationClass();


                Microsoft.Office.Interop.Word.Document myDoc = wordApp.Documents.Add(ref missing, ref missing,
                                                                                     ref missing, ref missing);
                     
                Range rng = myDoc.Range(ref start1, ref missing);

                try
                {
                  
                    const char newLine = (char) 11;

                    myDoc.SaveAs(ref fileStream, 
                    ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, 
                    ref missing,
                    ref missing,
                    ref missing, ref missing, ref missing);

C#
rng.InsertAfter(newLine.ToString());
                    rng.InsertBefore(newLine.ToString());
                    rng.InsertBefore(newLine + LabelPosition.Text + " " + LabelFirstName.Text + " " +
                                     LabelLastName.Text + newLine + LabelAbout.Text);
                    rng.InsertBefore(newLine + Label3StrongAbout.Text);
                    string imageKnowItLogo = Loggo.ImageUrl;
                    rng.InlineShapes.AddPicture(imageKnowItLogo, ref missing, ref missing, ref missing);
                    rng.InsertBefore(newLine.ToString());

C#
Response.ContentType = "Application/msword";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileName);
                Response.TransmitFile(Server.MapPath("~/Upload/") + strFileName);
                Response.End(); 
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900