Automating MS word, not able to view when I run under IIS

Mar 16 2010 8:54 AM
Hi
I am trying to create a report after extracting some of the data from radgrid when the user clicks a row.

The code in ASPX isa s follows

<telerik:RadGrid ID="LeaveTable" AllowPaging="true" AllowSorting="True" runat="server" AutoGenerateColumns="false" GridLines="Both" CssClass="RadGridCustomClass" OnItemCommand="LeaveTable_ItemCommand">

The item command event is fired when the user clicks a cell or a row in radgrid.
 I extract some of the data from the radgrid and populate it in the template word document and open the same at the client side.

The word document is opening when I run normally that is under a port like
http://www.localhost:4036/Eportal/lodi_aspx

But when I run under IIS like http://www.localhost/Eportal/Lodi.aspx I am not able to see the word document ttaht is generated but the event is fired up.

What property I need to set in the radgrid so that when I run, I can see the word document


protected
void LeaveTable_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "RowClick" && e.Item is GridDataItem)
{
e.Item.Selected =
true;
//RadGrid LeaveOpenGrid = (RadGrid)LeaveOpenSumm.FindItemByValue("LeaveOpen").FindControl("LeaveTable");
//LeaveOpenGrid.MasterTableView.ExportToExcel();

// Word document created at run time
GridDataItem dataItem = e.Item as GridDataItem;
TableCell cell = dataItem["First_Name"];
int a = e.Item.ItemIndex;
String F_name = Caseconv(cell.Text.ToString().Trim());
cell = dataItem[
"Last_Name"];
String L_name = Caseconv(cell.Text.ToString().Trim());
String Full_Name = F_name + " " + L_name;
 
 
cell = dataItem[
"LN1"];
String Address1 = Caseconv(cell.Text.ToString().Trim());
cell = dataItem[
"LN3"];
String Address2 = Caseconv(cell.Text.ToString().Trim());
String F_Address = Address1 + ", " + Address2;
cell = dataItem[
"City"];
String City = Caseconv(cell.Text.ToString().Trim());
cell = dataItem[
"State"];
string State = cell.Text.ToString().Trim();
 
 
cell = dataItem[
"Zip"];
string Zipcode = cell.Text.ToString().Trim();
cell = dataItem[
"Ealiest"];
string Earliest_Date = cell.Text.ToString();
cell = dataItem[
"Lastest"];
string Lastest_Date = cell.Text.ToString();
cell = dataItem[
"Number"];
string Leave_Number_Days = cell.Text.ToString();
String S_Address = City + ", " + State + ", " + Zipcode;
String DtTime;
DateTime dt = DateTime.Now;
int Year = dt.Year;
int Month = dt.Month;
int Day = dt.Day;
string MonthS = " ";
switch (Month)
{
case 1:
MonthS =
"january";
break;
case 2:
MonthS =
"Febraury";
break;
case 3:
MonthS =
"March";
break;
case 4:
MonthS =
"April";
break;
case 5:
MonthS =
"May";
break;
case 6:
MonthS =
"June";
break;
case 7:
MonthS =
"July";
break;
case 8:
MonthS =
"August";
break;
case 9:
MonthS =
"September";
break;
case 10:
MonthS =
"October";
break;
case 11:
MonthS =
"November";
break;
case 12:
MonthS =
"December";
break;
}
 
 
DtTime = MonthS +
" " + Day + ", " + Year;


object missing = System.Reflection.Missing.Value;


Microsoft.Office.Interop.Word.
Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
//object filepath = "C://EPortal//EPortal//EPortal//App_Themes//Theme1//Images//Sample_Lodi_Ltr.docx";
object filepath = Server.MapPath("~/App_Themes/Theme1/Images/Sample_Lodi_Ltr.docx");
object oTrue = true;
object ofalse = false;
Microsoft.Office.Interop.Word.
Document adoc = null;
adoc = wordApp.Documents.Open(
ref filepath, ref missing, ref oTrue, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing,ref oTrue , ref missing, ref missing,
ref missing, ref missing);
adoc.Activate();
wordApp.Visible =
true;
this.FindAndReplace(wordApp, "<Date>", DtTime);
this.FindAndReplace(wordApp, "<Last_Name>", L_name);
this.FindAndReplace(wordApp, "<Full_Name>", Full_Name);
this.FindAndReplace(wordApp, "<Address1>", F_Address);
this.FindAndReplace(wordApp, "<Zip_Address>", S_Address);
this.FindAndReplace(wordApp, "<Number_Days>", Leave_Number_Days);
this.FindAndReplace(wordApp, "<Ealiest>", Earliest_Date);
this.FindAndReplace(wordApp, "<Lastest>", Lastest_Date);
this.FindAndReplace(wordApp, "<Numberof_Days>", Leave_Number_Days);
}
}


private
void FindAndReplace(Microsoft.Office.Interop.Word.Application wordApp,
object findText, object replaceText)
{
object matchCase = true;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundsLike = false;
object matchAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;
wordApp.Selection.Find.Execute(
ref findText, ref matchCase,
ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
ref matchAllWordForms, ref forward, ref wrap, ref format,
ref replaceText, ref replace, ref matchKashida,
ref matchDiacritics,
ref matchAlefHamza, ref matchControl);
}


The word document code

/********************** SAMPLE_LODI_LTR.DOCx**********************************************/

 

 

 

 

<Date>

 

 

<Full_Name>

<Address1>

<Zip_Address>

 

 

Dear <Last_Name>,

 

In a review of pending line of duty injury (LODI) absences, we have discovered that you have <Number_Days> pending LODI day(s) that need to be reconciled.  The absences occurred during the following period(s):

 

<Ealiest> - <Lastest>  (<Numberof_Days> days)

 

As of the date of this letter, we have not received the necessary LODI paperwork to make a determination on these dates.  You must work with your school secretary to submit the proper LODI paperwork to the HR Connect Leaves Administration Office within 60 days of the date of this letter so that your case can be reviewed.  When submitting this paperwork, we ask that your school secretary include a copy of this letter.  Please see the attached guide concerning what paperwork must be completed and by whom.

 

Failure to submit the proper documentation may result in either a reduction in your CAR balance or payroll deduction, provided you do not have enough CAR days to cover the absences.  Please note that if we receive the requested information from you at a date beyond the deadline, your case may be reopened for review.

 

Should you have any questions about the information in this letter or the LODI approval process, please feel free to contact HR Connect at (718) 935-4000.  We recommend that you a keep a copy of this notice for your personal records.

 

Sincerely,

 

 


 /****************************************************************/ 


Answers (1)