This is a migrated thread and some comments may be shown as answers.

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

3 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cristian
Top achievements
Rank 1
Cristian asked on 01 Aug 2011, 09:01 PM
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");
               //}
           }
       }

3 Answers, 1 is accepted

Sort by
0
Fawad
Top achievements
Rank 1
answered on 23 Aug 2011, 02:22 PM
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.
0
Andy Green
Top achievements
Rank 2
answered on 26 Sep 2012, 02:07 PM
Hi

Did anyone figure thsi out?

Andy
0
Kostadin
Telerik team
answered on 01 Oct 2012, 12:19 PM
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.
Tags
Grid
Asked by
Cristian
Top achievements
Rank 1
Answers by
Fawad
Top achievements
Rank 1
Andy Green
Top achievements
Rank 2
Kostadin
Telerik team
Share this question
or