保存为工作时无法打开Word文档,第二次保存时无法获取错误 [英] Cannot Open Word Document when save as work , when save second time get error

查看:107
本文介绍了保存为工作时无法打开Word文档,第二次保存时无法获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当按下genarate按钮时.Doc

i得到我可以打开或保存

尝试打开时我收到此错误



Word在尝试打开文件时遇到错误。

尝试这些sugesstions。

*检查文档或驱动器的文件权限

*确保有足够的可用内存和磁盘空间。

*使用文本恢复转换打开文件




在执行保存时,它可以打开文档,但第二次尝试下载文档时保存,因为我收到错误

这不是有效的文件名。

请尝试下列办法中的一个或多个:

*检查路径以确保输入正确。

*选择文件和文件夹列表中的文件。




异常详细信息:System.Runtime.InteropServices.COMException:这不是有效的文件名。

请尝试下列办法中的一个或多个:

*检查路径以确保输入正确。

*从文件和文件夹列表中选择一个文件。




我下载单词的功能如下所示



When pressing button genarate do .Doc
i get that i can open or save
when trying to open i get this error

Word experienced an error trying to opet the file.
Try these sugesstions.
*Check the file permissions for the document or drive
*Make sure there is suffient free memory and disk space.
*Open the file with the text recovery convert


when doing save as, it works to open the document, but when trying second time to download the document with save as i get the error
This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.


Exception Details: System.Runtime.InteropServices.COMException: This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.


My function for downloading the to word looks like this

private void SetWordDocument()
        {
            string strFileName =
                CleanUp(LabelFirstName.Text + "_" + LabelLastName.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd") +
                        "." + DropDownListDownloadCv0.SelectedItem.Text);

            object fs = Server.MapPath("~/Upload/") + strFileName;

            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();
                    var myDoc = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                    object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
                    Range rng = myDoc.Range(ref start1, ref missing);

                    try
                    {
                        const char newLine = (char) 11;
                        myDoc.SaveAs(ref fs,
                                     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);


                        SetSkillAndLevelMax3();
                        for (int i = 0; i < RepeaterStrongestSkillsMax2.Controls.Count; i++)
                        {
                            var skill = (Label) RepeaterStrongestSkillsMax2.FindControl("skill" + i);
                            var pie = (Image) RepeaterStrongestSkillsMax2.FindControl("pie" + i);
                            if (skill != null & pie != null)
                            {
                                rng.InsertBefore(skill.Text);
                                string piee = pie.ImageUrl;
                                rng.InlineShapes.AddPicture(piee, ref missing, ref missing, ref missing);


                            }
                        }
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertBefore(newLine.ToString());
                        rng.InsertBefore(newLine + LabelPosition.Text + " " + LabelFirstName.Text + " " +
                                         LabelLastName.Text + newLine + LabelAbout.Text);
                        rng.InsertBefore(Label3Strong.Text);
                        foreach (var Label3StrongAbout in BulletedListStrong3About.Items)
                        {

                            rng.InsertBefore(newLine + Label3StrongAbout.ToString());
                        }

                        string imageKnowItLogo = Loggo.ImageUrl;
                        rng.InlineShapes.AddPicture(imageKnowItLogo, ref missing, ref missing, ref missing);
                        rng.InsertBefore(newLine.ToString());



                        rng.InsertBefore(newLine.ToString());


                        string imageProfPic = ImagePicture.ImageUrl;
                        rng.InlineShapes.AddPicture(imageProfPic, ref missing, ref missing, ref missing);
                        rng.InsertBefore(newLine.ToString());
                        rng.InsertAfter(newLine.ToString());
                        wordApp.Visible = true;





                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lbldateofbirth.Text + " " + LabelDateOfBirth.Text);
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lblphonenumber.Text + " " + LabelPhoneNumber.Text);
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lblemail.Text + " " + LabelEmail.Text);
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(newLine.ToString());

                        rng.InsertAfter(lbllanguages.Text);
                        rng.InsertAfter(newLine.ToString());


                        foreach (var vItem in BulletedListLanguages.Items)
                        {
                            rng.InsertAfter(vItem.ToString());

                            rng.InsertAfter(newLine.ToString());
                        }
                        rng.InsertAfter(newLine.ToString());


                        rng.InsertAfter(lblprevwork.Text);
                        rng.InsertAfter(newLine.ToString());

                        foreach (var vItem in BulletedListPrevWork.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lbleducations.Text);
                        rng.InsertAfter(newLine.ToString());

                        foreach (var vItem in BulletedListEducation.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lblcert.Text);
                        rng.InsertAfter(newLine.ToString());

                        foreach (var vItem in BulletedListCertifications.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lblcourses.Text);
                        rng.InsertAfter(newLine.ToString());

                        foreach (var vItem in BulletedListCourses.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }

                        rng.InsertAfter(newLine.ToString());
                        rng.InsertAfter(lblbusniess.Text);
                        rng.InsertAfter(newLine.ToString());

                        foreach (var vItem in BulletedListBusiness.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        rng.InsertAfter(newLine.ToString());
                        //////////////////////////////////////////////////////////
                        rng.InsertAfter(lbltechnicalskills.Text);
                        rng.InsertAfter(newLine.ToString());


                        rng.InsertAfter(LabelDataBas.Text);
                        rng.InsertAfter(newLine.ToString());
                        foreach (var vItem in BulletedListDataBase.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }

                        ////////////////////////////////////////////////////
                        rng.InsertAfter(lblprogramming.Text);
                        rng.InsertAfter(newLine.ToString());
                        foreach (var vItem in BulletedListProgramming.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        //////////////////////////////////////////////
                        rng.InsertAfter(lblmethods.Text);
                        rng.InsertAfter(newLine.ToString());
                        foreach (var vItem in BulletedListMethods.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        ////////////////////////////////////////////////////////
                        rng.InsertAfter(lbldevop.Text);
                        rng.InsertAfter(newLine.ToString());

                        foreach (var vItem in BulletedDevelopmentTools.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }
                        /////////////////////////////////////////////////////
                        rng.InsertAfter(lblwebserver.Text);
                        rng.InsertAfter(newLine.ToString());
                        foreach (var vItem in BulletedListWebServer.Items)
                        {
                            rng.InsertAfter(vItem.ToString());
                            rng.InsertAfter(newLine.ToString());
                        }

                        if (RadioButtonListChooseLang.SelectedItem.Text == "Swedish")
                        {
                            GetAlSwedishlAssigmentsDoc(theEmpl);

                            Label lbl = new Label
                                            {
                                                Text = newLine + "Uppdrag"
                                            };

                            rng.InsertAfter(lbl.Text);

                            for (int i = 0; i < RepeaterAssigments.Controls.Count; i++)
                            {
                                Label comp = (Label) RepeaterAssigments.FindControl("comp" + i);
                                Label sect = (Label) RepeaterAssigments.FindControl("sect" + i);
                                Label area = (Label) RepeaterAssigments.FindControl("are" + i);
                                Label from = (Label) RepeaterAssigments.FindControl("fro" + i);
                                Label to = (Label) RepeaterAssigments.FindControl("too" + i);
                                Label description = (Label) RepeaterAssigments.FindControl("des" + i);
                                Label tool = (Label) RepeaterAssigments.FindControl("tool" + i);
                                Label tec = (Label) RepeaterAssigments.FindControl("tec" + i);
                                Label reference = (Label) RepeaterAssigments.FindControl("ref" + i);

                                Label franManad = (Label) RepeaterAssigments.FindControl("franmanad" + i);
                                Label tillManad = (Label) RepeaterAssigments.FindControl("tillmanad" + i);
                                Label kundnytta = (Label) RepeaterAssigments.FindControl("kundnyttaSve" + i);
                                Label arbetsupgifter = (Label) RepeaterAssigments.FindControl("arbetsuppgifterSve" + i);
                                Label roll = (Label) RepeaterAssigments.FindControl("rollSve" + i);


                                Literal namesectorLit = (Literal) RepeaterAssigments.FindControl("NamesectorLit" + i);
                                Literal nameAreaLit = (Literal) RepeaterAssigments.FindControl("NameAreaLit" + i);
                                Literal nameTechLit = (Literal) RepeaterAssigments.FindControl("NameTechLit" + i);
                                Literal nameToolLite = (Literal) RepeaterAssigments.FindControl("NameToolLit" + i);
                                Literal nameRefLit = (Literal) RepeaterAssigments.FindControl("NameRefLit" + i);

                                Literal arbetsuppgifterLit =
                                    (Literal) RepeaterAssigments.FindControl("arbetsuppgifter" + i);
                                Literal rollLit = (Literal) RepeaterAssigments.FindControl("roll" + i);
                                Literal uppdragLit = (Literal) RepeaterAssigments.FindControl("updragSve" + i);
                                Literal kundnyttaLit = (Literal) RepeaterAssigments.FindControl("NyttaKundSve" + i);


                                if (comp != null && from != null
                                    && to != null && description != null && tool != null && tec != null

                                    && nameTechLit != null && nameToolLite != null &&
                                    nameRefLit != null && franManad != null && tillManad != null && kundnytta != null &&
                                    arbetsupgifter != null
                                    && arbetsuppgifterLit != null && rollLit != null
                                    && uppdragLit != null && kundnyttaLit != null && roll != null)
                                {

                                    rng.InsertAfter(newLine + comp.Text);
                                    rng.InsertAfter(from.Text);
                                    rng.InsertAfter(to.Text + newLine);

                                    rng.InsertAfter(nameToolLite.Text);

                                    rng.InsertAfter(tool.Text + newLine);

                                    rng.InsertAfter(nameTechLit.Text);
                                    rng.InsertAfter(tec.Text + newLine);



                                    rng.InsertAfter(franManad.Text);
                                    rng.InsertAfter(tillManad.Text);
                                    rng.InsertAfter(kundnyttaLit.Text);
                                    rng.InsertAfter(kundnytta.Text);
                                    rng.InsertAfter(arbetsuppgifterLit.Text);
                                    rng.InsertAfter(arbetsupgifter.Text);
                                    rng.InsertAfter(rollLit.Text);
                                    rng.InsertAfter(roll.Text);
                                    rng.InsertAfter(description.Text + newLine);
                                    rng.InsertAfter(uppdragLit.Text);


                                    Image image = new Image
                                                      {
                                                          ImageUrl =
                                                              SPContext.Current.Web.Url + "/" +
                                                              SPContext.Current.File.Url +
                                                              "~/_layouts/images/Cv.Knowit/img_line.png"
                                                      };
                                    //rng.InsertAfter(image.ImageUrl);
                                    rng.InlineShapes.AddPicture(image.ImageUrl, ref missing, ref missing,
                                                                ref missing);

                                }
                                if (sect == null && namesectorLit == null
                                    && reference == null && nameRefLit == null &&
                                    nameAreaLit == null && area != null)
                                {

                                }
                                if (sect != null && namesectorLit != null
                                    && reference != null && nameRefLit != null &&
                                    nameAreaLit != null && area != null)
                                {
                                    rng.InsertAfter(namesectorLit.Text);
                                    rng.InsertAfter(sect.Text + newLine);
                                    rng.InsertAfter(nameAreaLit.Text);
                                    rng.InsertAfter(area.Text + newLine);
                                    rng.InsertAfter(nameRefLit.Text);
                                    rng.InsertAfter(reference.Text + newLine);
                                }
                            }
                        }




                        else if (RadioButtonListChooseLang.SelectedItem.Text == "English")
                        {
                            GetAlEnglishAssigmentsDoc(theEmpl);

                            Label lbl = new Label
                                            {
                                                Text = newLine + "Assigments"
                                            };

                            rng.InsertAfter(lbl.Text);

                            for (int i = 0; i < RepeaterAssigments.Controls.Count; i++)
                            {
                                Label comp = (Label) RepeaterAssigments.FindControl("comp" + i);
                                Label sect = (Label) RepeaterAssigments.FindControl("sect" + i);
                                Label area = (Label) RepeaterAssigments.FindControl("are" + i);
                                Label from = (Label) RepeaterAssigments.FindControl("fro" + i);
                                Label to = (Label) RepeaterAssigments.FindControl("too" + i);
                                Label description = (Label) RepeaterAssigments.FindControl("des" + i);
                                Label tool = (Label) RepeaterAssigments.FindControl("tool" + i);
                                Label tec = (Label) RepeaterAssigments.FindControl("tec" + i);
                                Label reference = (Label) RepeaterAssigments.FindControl("ref" + i);
                                Literal namesectorLit =
                                    (Literal) RepeaterAssigments.FindControl("NamesectorLit" + i);
                                Literal nameAreaLit = (Literal) RepeaterAssigments.FindControl("NameAreaLit" + i);
                                Literal nameTechLit = (Literal) RepeaterAssigments.FindControl("NameTechLit" + i);
                                Literal nameToolLite = (Literal) RepeaterAssigments.FindControl("NameToolLit" + i);
                                Literal nameRefLit = (Literal) RepeaterAssigments.FindControl("NameRefLit" + i);




                                if (comp != null && sect != null && area != null && from != null
                                    && to != null && description != null && tool != null && tec != null &&
                                    reference != null
                                    && namesectorLit != null
                                    && nameAreaLit != null && nameTechLit != null && nameToolLite != null &&
                                    nameRefLit != null)
                                {

                                    rng.InsertAfter(newLine + comp.Text);
                                    rng.InsertAfter(namesectorLit.Text);

                                    rng.InsertAfter(sect.Text + newLine);

                                    rng.InsertAfter(nameAreaLit.Text);
                                    rng.InsertAfter(area.Text + newLine);
                                    rng.InsertAfter(from.Text);
                                    rng.InsertAfter(to.Text + newLine);
                                    rng.InsertAfter(description.Text + newLine);
                                    rng.InsertAfter(nameToolLite.Text);

                                    rng.InsertAfter(tool.Text + newLine);

                                    rng.InsertAfter(nameTechLit.Text);
                                    rng.InsertAfter(tec.Text + newLine);

                                    rng.InsertAfter(nameRefLit.Text);
                                    rng.InsertAfter(reference.Text + newLine);

                                    Image image = new Image
                                                      {
                                                          ImageUrl =
                                                              SPContext.Current.Web.Url + "/" +
                                                              SPContext.Current.File.Url +
                                                              "~/_layouts/images/Cv.Knowit/img_line.png"
                                                      };
                                    
                                    rng.InlineShapes.AddPicture(image.ImageUrl, ref missing, ref missing,
                                                                ref missing);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    finally
                    {
                        myDoc.Save();

                        myDoc.Close(ref doNotSaveChanges, ref missing, ref missing);


                        if (RadioButtonListChooseLang.SelectedItem.Text == "Swedish")
                        {
                            RepeaterAssigments.Controls.Clear();
                            GetAlSwedishlAssigments(theEmpl);

                        }
                        else if (RadioButtonListChooseLang.SelectedItem.Text == "English")
                        {
                            RepeaterAssigments.Controls.Clear();
                            GetAlEnglishAssigments(theEmpl);

                        }
                    }

                }

                string path = fs.ToString();
                FileInfo file = new FileInfo(path);
                if (file.Exists)
                {
                    Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "application/msword";
                    Response.WriteFile(file.FullName);
                    Response.End();
                }
                else
                {
                    Response.Write("This file does not exist.");
                }
            }
        }

推荐答案

Make sure the file name is valid. Use the debugger and see what is the file name which you application tries to use to save the document, correct accordingly.



You already posted 83 question. After all, learn the art of asking questions in a productive way. The code you show is way too long, yet your post does not provide sufficient information. But, in this very case, we don’t need this information. It’s only you who needs it. You really need to know what’s the attempted file name, to fix it. In other words, you need to learn debugging, instead of asking questions like this one, which is not helpful.



—SA
Make sure the file name is valid. Use the debugger and see what is the file name which you application tries to use to save the document, correct accordingly.

You already posted 83 question. After all, learn the art of asking questions in a productive way. The code you show is way too long, yet your post does not provide sufficient information. But, in this very case, we don't need this information. It's only you who needs it. You really need to know what's the attempted file name, to fix it. In other words, you need to learn debugging, instead of asking questions like this one, which is not helpful.

—SA


You may get rid of this error owing to corrupt .doc file fixer



This solution [spam link removed please report the account as a spammer] will solve your trouble
You may get rid of this error owing to corrupt .doc file fixer

This solution [spam link removed please report the account as a spammer] will solve your trouble


这篇关于保存为工作时无法打开Word文档,第二次保存时无法获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆