Error: We could not find the file. Is it possible that it has been moved, renamed or deleted? [closed]

0

I have a project in asp.net C #, I want to create a Word document with the data that the user entered in the Web Form.

It gives me a route error: Sorry, we could not find the file. Is it possible that it has been moved, renamed or deleted?

The error marks me on the line:

Word.Document ObjDoc = ObjWord.Documents.Open(parametro,ObjMiss);

I have modified it several times and it keeps giving me the same error.

This is my code:

   protected void btnguardar_Click(object sender, EventArgs e)
    {
        object ObjMiss = System.Reflection.Missing.Value;
        Word.Application ObjWord = new Word.Application();
        string ruta = Server.MapPath (@"\solicitud.docx");
        object parametro = ruta;
        object fecha1 = "fecha";
        object solicitud1 = "solicitud";
        object nomsol1 = "nomsol";
        object extsol1 = "correosol";
         object justif1 = "justif";
        object observ1 = "observ";

        Word.Document ObjDoc = ObjWord.Documents.Open(parametro,ObjMiss);
        Word.Range fech = ObjDoc.Bookmarks.get_Item(ref fecha1).Range;
        fech.Text = txtfechatenci.Text;
        Word.Range solicitu = ObjDoc.Bookmarks.get_Item(ref solicitud1).Range;
        solicitu.Text = txtfolio2.Text;
        Word.Range nomsolicitan = ObjDoc.Bookmarks.get_Item(ref nomsol1).Range;
        nomsolicitan.Text = txtnomseg.Text;
        Word.Range corrsolicit = ObjDoc.Bookmarks.get_Item(ref correosol1).Range;
        corrsolicit.Text = txtcorrseg.Text;
         Word.Range justific = ObjDoc.Bookmarks.get_Item(ref justif1).Range;
        justific.Text = txtjustifseg.Text;
        Word.Range observac = ObjDoc.Bookmarks.get_Item(ref observ1).Range;
        observac.Text = txtobserseg.Text;

        object rango1 = fech;
        object rango2 = solicitu;
        object rango3 = nomsolicitan;
        object rango6 = corrsolicit;
        object rango15 = justific;
        object rango16 = observac;

        ObjDoc.Bookmarks.Add("fecha", ref rango1);
        ObjDoc.Bookmarks.Add("solicitud", ref rango2);
        ObjDoc.Bookmarks.Add("nomsol", ref rango3);
        ObjDoc.Bookmarks.Add("correosol", ref rango4);
        ObjDoc.Bookmarks.Add("justif", ref rango15);
        ObjDoc.Bookmarks.Add("observ", ref rango16);

        ObjWord.Visible = true;

    }
    
asked by KlonDTS 06.03.2017 в 18:23
source

1 answer

1

Have you tried with string ruta = Server.MapPath (@"~/solicitud.docx"); (with ~ at the beginning)? This gives you not the "desktop" folder of your user, but the base path of your web application, for example, C:\Users\TU_USUARIO\Documents\Visual Studio 2015\Projects\Proyecto Web\Proyecto Web , so you can try to put the document there and try to do the operations there. You can check here how Server.MapPath works .

Now, you can create within the project a folder that is specific to that (those) file (s) and point there with Server.MapPath (@"~/docs/solicitud.docx"); .

    
answered by 06.03.2017 / 19:29
source