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

RadGrid Open Word

2 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 07 Jul 2009, 08:15 PM
I was wondering if there was an example of a RadGrid w/ a link that opens up a word document.

Thanks for the help.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jul 2009, 05:57 AM
Hi Robert,

I hope you are trying to open a word document on clicking a linkbutton in a Grid. If so try setting the CommandName for the GridButtonColumn and then in the ItemCommand Event you can write the code to open the word document. Here is a sample code which I tried. You may alter the logic accordingly.

ASPX:
 
<telerik:GridButtonColumn CommandName="File" DataTextField="FileName" HeaderText="ButtonColumn"  ></telerik:GridButtonColumn> 

CS:
 
 
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
 
     if (e.CommandName == "File"
      { 
        string filename = e.CommandSource.ToString(); 
                
                // get the file path 
                string path; 
                
                //checking whether file is exist in hard drive 
                ShowFile(filename, path); 
 
      } 
 
    } 
 
  private void ShowFile(string filename, string path) 
        { 
            if (File.Exists(path)) 
            { 
                //Response.ContentType = "application/ms-word"; 
                Response.AddHeader("content-disposition""attachment; filename=" + filename); 
 
                FileStream sourceFile = new FileStream(path, FileMode.Open); 
                long FileSize; 
                FileSize = sourceFile.Length; 
                byte[] getContent = new byte[(int)FileSize]; 
                sourceFile.Read(getContent, 0, (int)sourceFile.Length); 
                sourceFile.Close(); 
                Response.BinaryWrite(getContent); 
            } 
            
        }  


Thanks
Shinu

0
Robert
Top achievements
Rank 1
answered on 08 Jul 2009, 12:44 PM
I got the error: Sys.WebForms.PageRequestManagerParserErrorException...

I'm also using Masterpages.  The fix was:

 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

 

 

<script type="text/javascript">

 

 

function mngRequestStarted(ajaxManager, eventArgs) {

 

 

if (eventArgs.EventTarget.indexOf("btnItemName") != -1) {

 

eventArgs.EnableAjax =

false;

 

}

}

 

</script>

 

 

</telerik:RadCodeBlock>

Thanks so much for your quick response.

Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Share this question
or