Wednesday, January 29, 2014

Open PDF/Word/Image files in respective softwares in sharepoint 2010

Dear Omkar,


Thank you so much for your reply.


I have to achieve this using coding. My image button is inside a gridview. When I click the image button from the page it should open the document in PDF/Word reader.


I have written the below code, but since the code resides in server, when iam clicking the image button from client side, the document is not opening. This is getting opened in the server and I could see the process running under processes tab of the task manager.



<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False"
OnRowDataBound="gvIdentify_Databound" OnRowCommand="gvIdentify_RowCommand" >
<HeaderStyle BackColor="#4b6985" ForeColor="#ffffff" />
<AlternatingRowStyle BackColor="#e7f0f9" />
<Columns>
<asp:TemplateField HeaderText="Status of the artifact">
<ItemTemplate>
<asp:ImageButton ID="lnkDigit" runat="server" CommandName="DigitImageClick" CommandArgument='<%#Bind("Asset_ID")%>' CausesValidation="false"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



on row databound i wrote the below code



protected void gvIdentify_RowCommand(object sender, GridViewCommandEventArgs e)
{

try
{

if (e.CommandName == "DigitImageClick")
{

clsImpersonation objImp = new clsImpersonation();
string impUserName = ConfigurationSettings.AppSettings["impUserName"];
string impPassword = ConfigurationSettings.AppSettings["impPassword"];
string impDomain = ConfigurationSettings.AppSettings["impDomain"];
if (objImp.impersonateValidUser(impUserName, impDomain, impPassword))
{
string strPDFFile = @"\\ServerName\MyFolderName\Test\OctoberTest.pdf";
System.Diagnostics.Process.Start(strPDFFile);
}
objImp.undoImpersonation();
}
}
catch (Exception ex)
{
throw ex;
}
}





No comments:

Post a Comment