How to open pdf file uploaded to server in asp.net ajax radgrid?

4 posts, 0 answers
  1. Cristian
    Cristian  avatar
    46 posts
    Member since:
    May 2011

    Posted 01 Aug 2011 Link to this post

    Hi guys, I'm having some trouble opening a pdf file when a gridbuttoncolumn is pressed. This is my code I have to open it
    if (e.CommandName == "Ver")
             {
                 string Servidor = Request.Url.GetLeftPart(UriPartial.Authority);
                 string fullUrl = Servidor + Session["strUrl"];
                 OpenFile(fullUrl);
             }
    But when I run it I get the next error message "The relative virtual path 'http:/localhost:50422/docs/28-grant application.pdf' is not allowed here." I save the file previously and now I want to open it but I can't do'it. Can you point me to the right direction please.
    This is my code to save the document.
    var usuarioSesion = (Usuario)Session["usuarioSesion"];
               var dbContext = new BD_SSEGUAEntities();
               string strUrl;
               int exp = Convert.ToInt32(Session["ExpEmp"]);
               int folio = Convert.ToInt32(Session["Foliosol"]);
               var newDoc = new Documento();
               foreach (UploadedFile file in RadUpload1.UploadedFiles)
               {
                  // var ResultSol = new Solicitud();
                   var fileName = folio + "-" + file.GetName().ToLower();
                   file.SaveAs(MapPath(@"~/docs/" + fileName));
                   strUrl = "/docs/" + fileName;
                   //MapPath(@"/docs/")+file.GetName();// + ResultSol.fiIdSolicitud + "-" +
                   if (RadUpload1.InvalidFiles.Count == 0 && RadComboBox1.SelectedValue!=null )
                   {
                       try
                       {
                           var doc = new Documento
                                         {
                                             fiIdSolicitud = folio,
                                             fiAnioSolicitud = (short) DateTime.Now.Year,
                                             fiIdTipoDocumento = (byte) TipoDoc,
                                             fiIdEdoDocto = 1,
                                             fdFchRegDocto = DateTime.Now,
                                             fiUsrRegDocto = usuarioSesion.Expediente,
                                             fcURLdocumento = strUrl,
                                         };
                           dbContext.Documento.AddObject(doc);
                           dbContext.SaveChanges();
                           Alerta("El documento se guardó de forma correcta");
                            
                             
                       }
                       catch (Exception ex)
                       {
                           Alerta(ex.Message);
                       }
                       llenaGridDocs();
                   }
                   else
                   {
                       Alerta("Captura los todos los datos");
                   }
                   //  else
                   //{
                   //    Alerta("Agrega un documento");
                   //}
               }
           }

  2. Fawad
    Fawad avatar
    38 posts
    Member since:
    May 2009

    Posted 23 Aug 2011 Link to this post

    Hi

    I have got the similar problem where I want to show a pdf file upon clicking of an image button in GridTemplateColumn, any help, admins?

    Regards.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 26 Sep 2012 Link to this post

    Hi

    Did anyone figure thsi out?

    Andy
  5. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 01 Oct 2012 Link to this post

    Hi,

    If you have the PDF file on your local machine or stored on a server you can add the path to the button's click event. You can do something as simple as the following, assuming you have acrobat installed.
    Response.Redirect("URL of the pdf file");

    All the best,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top