I have successfully add a new contact in outlook at a button click in C# in
website and it is working properly at the local system.
It mean to say that when I run the program then it is working properly but when I published the website for the other user then it gives the "server error."
So what should I do? Plz tell me .
The error message and the code which i m using is given below:--
The error message:-
Server Error in Application.
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true" />, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\intranetuat\0a58e002\6078546c\App_Web_1ra5ta-r.3.cs Line: 0
Stack Trace:
[UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.]
ContactPersonalDetail..ctor() +68
ASP.contactpersonaldetail_aspx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\intranetuat\0a58e002\6078546c\App_Web_1ra5ta-r.3.cs:0
__ASP.FastObjectFactory_app_web_1ra5ta_r.Create_ASP_contactpersonaldetail_aspx() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\intranetuat\0a58e002\6078546c\App_Web_1ra5ta-r.12.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
The code is:--
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Web.Configuration;
using OutlookInterop = Microsoft.Office.Interop.Outlook;
public partial class ContactPersonalDetail : System.Web.UI.Page
{
SqlConnection cnn = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
private string uploadDirectory;
OutlookInterop.ApplicationClass app = new OutlookInterop.ApplicationClass();
public bool CheckCustomFolderExisits()
{
OutlookInterop.NameSpace ns = app.GetNamespace("MAPI");
OutlookInterop.MAPIFolder contactsFolder = app.ActiveExplorer().Session.GetDefaultFolder(OutlookInterop.OlDefaultFolders.olFolderContacts);
foreach (OutlookInterop.MAPIFolder subFolder in contactsFolder.Folders)
{
if (subFolder.Name == "MAPI")
{
return true;
}
else
return false;
}
return false;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lnkSaveasoutlook_Click(object sender, EventArgs e)
{
try
{
OutlookInterop.ContactItem newContact = (OutlookInterop.ContactItem)app.CreateItem(OutlookInterop.OlItemType.olContactItem);
newContact.FirstName = (txtfirstname.Text);
newContact.LastName = (txtlastname.Text);
newContact.Email1Address = (txtemail.Text);
newContact.WebPage = (txtwebpage.Text);
newContact.Display(true);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}