I am trying to open outlook from code behind but everything works fine for me when i run it from my local machine but i am getting an error when i deployed to the server. I am getting this error:
"404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable."
I can't seem to figure out what the issue is so far. I need to use onrow command event so i can send a different email based on the command button that the user is selected. I just need the outlook to open and i am assigning programmatically the subject and body content and even the mailto. here is my code:
<asp:GridView ID="gvDetail" runat="server" CssClass="table table-hover table-bordered table-responsive" ForeColor="#333333" GridLines="None"
CellPadding="4" PageSize="200" OnRowCommand="GridViews_RowCommand" OnPageIndexChanging="OnPaging_gvDetail"
AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" EnableViewState="True">
<AlternatingRowStyle BackColor="#F3F3F3" />
<Columns>
<asp:BoundField DataField="contract_name" HeaderText="Category" />
<asp:BoundField DataField="vendor_name" HeaderText="Vendor Name" />
<asp:ButtonField HeaderText="Reconciliation of Spend Metrics" ButtonType="Image" ImageUrl="~/img/mail.png" ControlStyle-Width="30px" ControlStyle-Height="30px" CommandName="Select" />
<asp:ButtonField HeaderText="Request Call/Meeting with Supplier" ButtonType="Image" ImageUrl="~/img/mail.png" ControlStyle-Width="30px" ControlStyle-Height="30px" CommandName="Select1" />
</Columns>
<HeaderStyle CssClass="GridviewScrollHeader" BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle CssClass="GridviewScrollItem" ForeColor="#000066" />
</asp:GridView>
code behind
protected void GridViews_RowCommand(object sender, GridViewCommandEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ToString());
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
if (e.CommandName == "Select")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
string contractname = gvDetail.Rows[rowIndex].Cells[0].Text;
string vendorname = gvDetail.Rows[rowIndex].Cells[1].Text;
oMsg.Subject = "test";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.HTMLBody = "<p> "test..." + Environment.NewLine + "</p>"; //Here comes your body;
oMsg.Display(false); //In order to display it in modal inspector change the argument to true
}
}