I am creating an import / export tool for CRM using C#.
Sometimes, I am facing to an import error, with only this message "Solution manifest import: FAILURE" in my catch. I tried to cast it to its type (FaultException), but I haven't any more details.
If I do the import of the same file directly in CRM, I have a better error message (this one for exemple : "Import of solution xxxx failed. The following components are missing in yout system [...]").
Is there a way to get this complete message ?
Here is my code :
try
{
_serviceProxy.Execute(impSolReq);
}
catch (Exception ex)
{
if (ex is FaultException<OrganizationServiceFault>)
MessageBox.Show("Error during import. More details: " + ((FaultException<OrganizationServiceFault>)ex).Detail);
else
MessageBox.Show("Error during import. More details: " + ex.Message);
}
Thanks for your answers !
Dynamics CRM solutions are imported using the ImportSolutionRequest.
The ImportSolutionRequest has a property containing the ID of the solution import job. You need this ID to be able to monitor the progress of the job and to get error details when the import fails.
Instantiation of the request could look like this:
Guid importJobId = Guid.NewGuid();
var request = new ImportSolutionRequest
{
ConvertToManaged = true,
CustomizationFile = buffer, // a byte[] array holding the solution contents
ImportJobId = importJobId,
OverwriteUnmanagedCustomizations = true,
PublishWorkflows = true,
SkipProductUpdateDependencies = false
};
Execute the request. When an import error occurs, you can retrieve the error details using the job id.
try
{
_service.Execute(request);
}
catch (FaultException<OrganizationServiceFault> ex)
{
if (ex.Detail.ErrorCode == -2147188685) // ImportSolutionError
{
Entity job = _service.Retrieve("importjob", importJobId, new ColumnSet { AllColumns = true });
// TODO: process job error details.
}
throw;
}
Attribute importjob.data contains an XML document with the details you are looking for.
The ImportSolutionRequest is executed synchronously and can easily time-out. Time-outs however can safely be ignored, because the import process continues to run in the background. You can track progress by retrieving the import job record at regular intervals. As long as attribute importjob.completedon is null, the job is still running.
Related
I have a console application which tries to upload a document into a share point document library list.
I am successfully able to do it and also I am able to fill one of the custom Column(Column name is : "Category") value while uploading the file using C#.
I have tried to fill another custom column(Column name is : "Related Assets") value using the same procedure but i get the error stating the provided column name does not exist but when i see in actual share point portal it does exist.
So not able to solve this issue. Even i tried couple of methods as given below and i get same error message in terms of the column does not exist or it has been deleted or not able to recognize it.
Please find the screenshot of SharePoint showing the list of columns:
Please find the code i have till now which upload the document into SharePoint portal.
public static async Task<string> UploadReleaseNoteDocumentintoSpPortal(string releasenotefilepath, string releasenotefilename, string clientid, string clientsecret)
{
string status = string.Empty;
try
{
Console.WriteLine("Trying to Upload Release note file into Share Point Portal...");
string siteUrl = "<<Sp site URL>>";
Console.WriteLine("Connecting to Share Point Portal...");
var ClientContext = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientid, clientsecret);
ClientContext.Load(ClientContext.Web, p => p.Title);
await ClientContext.ExecuteQueryAsync();
Console.WriteLine(ClientContext.Web.Title);
var web = ClientContext.Web;
Console.WriteLine("Connected successfully to Share Point Portal...");
List DocumentsList = web.Lists.GetByTitle("Accelerators Documents");
ClientContext.Load(DocumentsList.RootFolder);
await ClientContext.ExecuteQueryAsync();
Console.WriteLine("Reading and loading the list named : Accelerators Documents from SP");
Console.WriteLine("Converting the release note document into byte array");
byte[] bytes = System.IO.File.ReadAllBytes(releasenotefilepath);
MemoryStream stream = new MemoryStream(bytes);
Console.WriteLine("Storing the release note Data into File Create information object of SharePoint");
FileCreationInformation FileCreateInfo = new FileCreationInformation();
FileCreateInfo.Content = bytes;
FileCreateInfo.ContentStream = stream;
FileCreateInfo.Overwrite = true;
FileCreateInfo.Url = DocumentsList.RootFolder.ServerRelativeUrl + #"\" + releasenotefilename;
Console.WriteLine("Adding file to SharePoint");
var ReleaseNoteFiledata = DocumentsList.RootFolder.Files.Add(FileCreateInfo);
ReleaseNoteFiledata.Update();
ReleaseNoteFiledata.ListItemAllFields["Category"] = "Release Notes";
//ReleaseNoteFiledata.ListItemAllFields["Related Assets"] = "<<Desired Value>>";
//IN Above commented line i get the error stating Microsoft.SharePoint.Client.ServerException:
//'Column 'Related Assets' does not exist. It may have been deleted by another user.
//But in actual site if we see it exists as you can see in above screenshot
ReleaseNoteFiledata.ListItemAllFields.Update();
ClientContext.Load(ReleaseNoteFiledata);
await ClientContext.ExecuteQueryAsync();
Console.WriteLine("Adding file to SharePoint Completed Successfully...");
return status = "Successful";
}
catch (Exception ex)
{
Console.WriteLine("Exception occured while trying to upload Release note file into CoP Portal :" + ex.Message);
return status = "Error/Exception";
}
}
Please find the error message i get while trying to add value to another custom column present in SharePoint:
Microsoft.SharePoint.Client.ServerException: 'Column 'Related Assets' does not exist. It may have been deleted by another user.
Even if i use the ReleaseNoteFiledata.SetFileProperties() and pass the values as a dictionary key value pair containing the column name and its value then also i get the same error for the second custom column. If i keep only the category custom column then it works perfectly without any issue as you can see in the screenshot above.
If i select the record and see the details or properties in the SharePoint the Related assets column symbol is some like in below screenshot:
Please let me know if the supporting documents are fine or still if my issue is not understandable so that i can re frame it or provide more screenshots.
Please help me in solving the above issue or how to make this column recognizable or readable or identifiable in the code.
Thanks in Advance
Regards
ChaitanyaNG
You need to use the internal name of the column 'Related Assets' in your code. It should be Related_x0020_Assets.
You could check the internal name of the column by go to list settings-> click the column, you would see the internal name in the url.
I am using Azure Information Protection Unified Labeling client to label emails. We are still using PGP in our environment and emails classified strictly confidential must be PGP encrypted.
When the email is sent, I try to find out, how the email is classified and trigger PGP encryption, when the classification is strictly confidential. This is done in an Outlook VSTO c# Add-in.
To find out the classification, I read the email header property "msip_labels" which is set by AIP and contains all necessary information. I am using the following procedure to read the headers. The code is far away from being perfect. I am just figuring out, how to get the value.:
private void GetHeaders()
{
var mail = (Outlook.MailItem)Application.ActiveInspector().CurrentItem;
var propertyAccessor = mail.PropertyAccessor;
try
{
var custom = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels");
}
catch(Exception ex)
{
var message = ex.Message;
}
}
I am able to read properties, set by another tool, but the AIP property is multiline. When the code is executed, I get the Error: Typeconflict. (Exception of HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Is there a way, to read multivalue properties? Here is an example of the msip_labels property (GUIDs replaced with XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX):
msip_labels: MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_Enabled=true;
MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_SetDate=2019-11-14T07:16:38Z;
MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_Method=Privileged;
MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_Name=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX;
MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_SiteId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX;
MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_ActionId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX;
MSIP_Label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_ContentBits=1
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_enabled: true
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_setdate: 2019-11-14T07:16:48Z
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_method: Privileged
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_name:
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_siteid:
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_actionid:
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
msip_label_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX_contentbits: 0
Finally I have figured out, how to create the property schema string, so it returns the right data type. Helpful for finding out the datatype was analyzing the item using Outlook Spy. The correct line of code with the right Schema String for querying msip_labels is:
var mSIPLabels = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F") as string;
after the property name, I had to pass the type descriptor 0x0000001F
And additional to this:
How to set a MIP Lablel to (Outlook VSTO) MailItem
public void SetMIP_LabelPublic(MailItem newMailItem)
{
var lblID = MipFileService.Label_Standard_Id; // <== your label ID
var tenantId = MipSettings.TenantId; //<== azur information tenant (your company) id
var mipMethod = "Privileged";
var dd = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.CreateSpecificCulture("en-us"));
var mipPropertyText = $"MSIP_Label_{lblID}_Enabled=true; "
+ $"MSIP_Label_{lblID}_SetDate={dd}; "
+ $"MSIP_Label_{lblID}_Method={mipMethod}; "
+ $"MSIP_Label_{lblID}_SiteId={tenantId}; ";
newMailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F", mipPropertyText);
}
I have an Outlook add-in that is working successfully for about 100 users. It interacts with our application and creates/updates Tasks and Appointment items. However, one client cannot get it to work for anyone who is not a network administrator. Through some logging, I can see that it works fine until it gets to the part where it should save the Task, and then it throws the infamous "The operation failed." error. I have tried in vain to get more error details by investigating inner exceptions and such, but "The operation failed." is all I can seem to get out of it.
To make it simpler to debug, I eliminated our application from the picture and wrote them a test add-in that just creates 9 tasks (hard-coded to "Task 1", "Task 2", etc.) and it fails in the same place with the same error. I have asked them to write a macro to see if a macro is able to create tasks for these users. I am awaiting their reply on that.
Anyway, I have been on MSDN for over a month trying to get help on the issue and nobody has been able to help. I am hoping someone here could shed some light. If you can provide any insight on what might be happening or suggestions to help me track down the problem, it would be greatly appreciated!
This is the function I am using to create the sample tasks in the test add-in:
private void CreateTasks()
{
int i = 1;
Outlook.TaskItem t = null;
Outlook.UserProperties ups = null;
Outlook.UserProperty up = null;
string name = string.Empty;
while (i < 10)
{
name = string.Format("Task {0}", i.ToString());
t = Application.CreateItem(Outlook.OlItemType.olTaskItem);
t.Subject = name;
t.Status = Outlook.OlTaskStatus.olTaskNotStarted;
t.Body = string.Format("Task {0} description", i.ToString());
t.Categories = "Test Task";
t.Importance = Outlook.OlImportance.olImportanceNormal;
t.ActualWork = 0;
t.TotalWork = 5 * 60;
//mimic dates that might come in main add-in
DateTime st = Convert.ToDateTime("12/10/2013");
st = st.AddDays(i);
t.StartDate = st;
DateTime end = Convert.ToDateTime("01/02/2014");
end = end.AddDays(i);
string EP = end.ToShortDateString() + " 5:00:00 PM";
end = Convert.ToDateTime(EP);
t.DueDate = end;
//mimic how we keep track of our items in the main add-in
ups = t.UserProperties;
up = ups.Find("ID");
if (up == null)
{
up = ups.Add("ID", Outlook.OlUserPropertyType.olText);
}
up.Value = string.Format("ID {0}", i.ToString());
//This is where the "The Operation Failed." error occurs on every single task.
try
{
((Outlook._TaskItem)t).Save();
}
catch (Exception ex)
{
//logs message to file
}
//Release objects
if (up != null) Marshal.ReleaseComObject(up);
if (t != null) Marshal.ReleaseComObject(t);
i++;
}
GC.Collect();
}
According to MSDN:
Saves the Microsoft Outlook item to the current folder or,
if this is a new item, to the Outlook default folder for the item type.
Does the "non administrator user" have access to this folder?
I'd hedge a bet it is something to do with Access permissions. This would be the first place to start.
Is this in an Exchange mailbox? I've seen this error before when connection to the server becomes spotty. If it is, see if the error occurs if you switch from cached mode to online mode. I don't think it's a code issue.
I am writing to a file, that is created for each date of the year, through code below. This code runs whenever, an unhandled exception occurs in an ASP.Net app. My problem is when many users are using the website, then this code could be hit due to several errors occurring at the same time, which could result in multiple requests to create or write to same file. What is the solution in this case so only one request executes the code related to writing to a file?
private void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
string errorGuid = Guid.NewGuid().ToString("D");
if (HttpContext.Current.Server.GetLastError() != null)
{
Exception err = HttpContext.Current.Server.GetLastError();
string header = String.Format("/*****\t\t{0}:{1}\t\t*****/", "Start", errorGuid);
string footer = String.Format("/*****\t\t{0}:{1}\t\t*****/", "End", errorGuid);
string errorText = String.Format("{0}{5}Exception DateTime: {1}{5}Reference #: {2}{5}Exception:{5}=========={5}{3}{5}{4}{5}", header, System.DateTime.Now, errorGuid, err.ToString(), footer, Environment.NewLine);
// '~/ErrorReports/Logs/ErrorLog.log' must exist, else we will get an error
using (System.IO.TextWriter write = new System.IO.StreamWriter(HttpContext.Current.Server.MapPath("~/ErrorReports/Logs/ErrorLog_" + DateTime.Now.ToShortDateString() + ".log"), true, System.Text.Encoding.UTF8))
{
write.WriteLine(errorText);
write.Close();
}
}
}
1 - you can use the singleton pattern and create a class that will handle this file creation/append or
2 - use "lock"
3 - as suggested, use elmah
How can I save an Access report in .net to the user's pc? I've tried using Access.SaveAsAXL, Docmd.OutputTo, and few other ways, but to no avail. The following is my latest attempt.
string dbname = "D:\\filename.mdb";
Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.Application();
oAccess.OpenCurrentDatabase(dbname, true);
oAccess.Visible = true;
var acFormatXLS = "Microsoft Excel (*.xls)";
string id = "tblJobs.JobID=" + (Convert.ToInt32(GetMaxJobID())).ToString();
try
{
oAccess.Run("BuildXAxisTimeLine", Convert.ToInt32(GetMaxJobID()));
oAccess.SaveAsAXL(Microsoft.Office.Interop.Access.AcObjectType.acReport, "rptChartData", "D:\\report.xls");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//oAccess.CloseCurrentDatabase();
}
The error i receive is:
hresult e_fail has been returned from a call to a com component
any help would be greatly appreciated. Thank you.
The followig code solved my problem. place this in the try section as shown above instead of oAccess.SaveAsAxl line of code and right under the .Run line of code.
oAccess.DoCmd.OpenReport("rptChartData", Microsoft.Office.Interop.Access.AcView.acViewPreview, null,id);
oAccess.DoCmd.OutputTo(Microsoft.Office.Interop.Access.AcOutputObjectType.acOutputReport, "rptChartData", acFormatXLS, "D:\\reportname.pdf",false, null, null);