How to create notes using EWS Managed API 2.0 - c#

Even looking into MSDN's Exchange 2013 - 101 Code Samples, I could not find an example creating notes using EWS Managed API 2.0. On Folders and items in EWS in Exchange, the most appropriate item type seems to me PostItem but my test failed trying to create such items in Notes folder. Or, is it possible there is no API for creating notes in this library?

A PostItem isn't the same as a note in the Notes folder. PostItem's represent items with a message class of IPM.Post. Notes, on the other hand, use the message class IPM.StickyNote. The managed API has no direct support for these items. You can retrieve them as EmailMessage objects, and you can even create them as EmailMessage objects if you manually set the required properties. Glen has a good write-up on his blog: http://gsexdev.blogspot.com/2009/07/creating-sticky-notes-in-ews-managed.html

Take a look at the PostItem, they should do what you want. PostItem
Sample
var items = new List<PostItem>();
for (int i = 0; i != 10; ++i)
{
var m = new PostItem(service);
m.Subject = "Note " + i.ToString();
m.Body = new MessageBody(BodyType.Text, "A test note");
m.Save();
}

var guid = new Guid("0006200E-0000-0000-C000-000000000046");
var colour = new ExtendedPropertyDefinition(guid, 0x8B00, MapiPropertyType.Integer);
var width = new ExtendedPropertyDefinition(guid, 0x8B02, MapiPropertyType.Integer);
var height = new ExtendedPropertyDefinition(guid, 0x8B03, MapiPropertyType.Integer);
var left = new ExtendedPropertyDefinition(guid, 0x8B04, MapiPropertyType.Integer);
var top = new ExtendedPropertyDefinition(guid, 0x8B05, MapiPropertyType.Integer);
var items = new List<EmailMessage>();
for (int i = 0; i != maxItems; ++i)
{
var m = new EmailMessage(service);
m.Subject = "Note " + i.ToString();
m.ItemClass = "IPM.StickyNote";
m.Body = new MessageBody(BodyType.Text, "A test note");
m.SetExtendedProperty(colour, 1);
m.SetExtendedProperty(width, 200);
m.SetExtendedProperty(height, 166);
m.SetExtendedProperty(left, 200);
m.SetExtendedProperty(top, 200);
items.Add(m);
}
var folder = Folder.Bind(service, WellKnownFolderName.Notes, new PropertySet());
var responses = service.CreateItems(items, folder.Id, MessageDisposition.SaveOnly, SendInvitationsMode.SendToNone);

Related

Passing multiple line items with GP webservice

Below is the code I'm working with to pass multiple line items to create sales order through GP Web service. I can pass single Line Item without any problem , but when I pass multiple Items it is only taking the last one. The array has around 5 Item ID and I'm passing fixed Quantity as 15, Need to make both dynamic. But for the testing purpose I'm trying like this. I know the problem with the creation/initialization of some web service objects. As novice to the entire set of things I couldn't find the exact problem.
C# Code
CompanyKey companyKey;
Context context;
SalesOrder salesOrder;
SalesDocumentTypeKey salesOrderType;
CustomerKey customerKey;
BatchKey batchKey;
// SalesOrderLine salesOrderLine;
ItemKey orderedItem;
Quantity orderedAmount;
Policy salesOrderCreatePolicy;
DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.UserName = "Admin";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Password = "pass";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Domain = "Gp";
System.ServiceModel.WSHttpBinding binding;
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);
context = new Context();
companyKey = new CompanyKey();
companyKey.Id = (1);
context.OrganizationKey = (OrganizationKey)companyKey;
salesOrder = new SalesOrder();
salesOrderType = new SalesDocumentTypeKey();
salesOrderType.Type = SalesDocumentType.Order;
salesOrder.DocumentTypeKey = salesOrderType;
customerKey = new CustomerKey();
customerKey.Id = "121001";
salesOrder.CustomerKey = customerKey;
batchKey = new BatchKey();
batchKey.Id = "RMS";
salesOrder.BatchKey = batchKey;
// SalesOrderLine[] orders = new SalesOrderLine[6];
SalesOrderLine[] lines = { };
for (int i = 1; i < 5; i++)
{
SalesOrderLine salesOrderLine = new SalesOrderLine();
orderedItem = new ItemKey();
orderedItem.Id = Arr[i].ToString();
salesOrderLine.ItemKey = orderedItem;
orderedAmount = new Quantity();
orderedAmount.Value = 15;
salesOrderLine.Quantity = orderedAmount;
lines = new SalesOrderLine[] { salesOrderLine };
MessageBox.Show(lines.Count().ToString());
}
salesOrder.Lines = lines;
//salesOrder.Lines = orders;
salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);
wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
if (wsDynamicsGP.State != CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
MessageBox.Show("Success");
lines = new SalesOrderLine[] { salesOrderLine }; will recreate the lines array object each time meaning you loose any previously added objects. Effectively only the final object in the loop is actually added.
Try using a List<T> like so:
SalesOrderLine[] lines = { }; Becomes List<SalesOrderLine> lines = new List<SalesOrderLine>();
lines = new SalesOrderLine[] { salesOrderLine }; Becomes: lines.Add(salesOrderLine);
If its important you end up with an array as the input:
salesOrder.Lines = lines; Becomes: salesOrder.Lines = lines.ToArray();

how do you update multiple NamedRanges via C# GoogleSheets API?

I'm able to update a single NamedRange using Update(), and multiple GridCoordinate ranges using BatchUpdate, but I can't work out how to update NamedRanges in a BatchUpdate. How is this done?
The single NamedRange update I can do like this:
ValueRange vr = new ValueRange();
vr.Range = "aRange";
var l1 = new List<object>();
l1.Add("Here");
IList<IList<object>> l2 = new List<IList<object>>();
l2.Add(l1);
vr.Values = l2;
var rqe2 = service.Spreadsheets.Values.Update(vr, spreadsheetId, "aRange");
rqe2.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
rqe2.Execute();
and a GridCoordinate via BatchUpdate I can do like this:
BatchUpdateSpreadsheetRequest busr = new BatchUpdateSpreadsheetRequest();
busr.Requests = new List<Request>();
Request r = new Request();
busr.Requests.Add(r);
r.UpdateCells = new UpdateCellsRequest();
var gc = new GridCoordinate();
gc.ColumnIndex = 0;
gc.RowIndex = 5;
gc.SheetId = 0;
r.UpdateCells.Start = gc;
r.UpdateCells.Fields = "*";
r.UpdateCells.Rows = new List<RowData>();
var rd = new RowData();
r.UpdateCells.Rows.Add(rd);
rd.Values = new List<CellData>();
var cd = new CellData();
cd.UserEnteredValue = new ExtendedValue();
cd.UserEnteredValue.StringValue = "UserEnteredValue";
rd.Values.Add(cd);
SpreadsheetsResource.BatchUpdateRequest bur = service.Spreadsheets.BatchUpdate(busr, spreadsheetId);
bur.Execute();
You're using two different kinds of updates above, values.update & spreadsheets.batchUpdate.
The values API collection works with A1 ranges, which include named ranges, sheet names, row numbers (1-based) and column letters. The spreadsheets API collection works with GridRange, GridCoordinate, DimensionRange, etc.. objects, all of which work with sheet IDs and row/column indexes (0-based).
If you'd like to do a batch update of values within named ranges, you want to use the values.batchUpdate API, not the spreadsheets.batchUpdate API.
The API in C# should be a fairly straightforward mapping of the info on the reference docs, probably using SpreadsheetsResource.ValuesResource.BatchUpdateRequest.

In CRM Dynamics 2013 how can I retrieve a list of accounts and create phone call activities against them for specific users

I have a scenario where I need to get a list of accounts from CRM and then create phone-call activities against those accounts, also assign/splitting them amongst four different users, please see my code so far and please guide me to a solution for this scenario.
public static void CreatePhoneCallActivitesForRelatedAccount(IOrganizationService service)
{
QueryExpression qe = new QueryExpression();
qe.EntityName = "account";
qe.ColumnSet = new ColumnSet("new_accountactionedstatus");
qe.Criteria.AddCondition("new_deliverystatus", ConditionOperator.Equal, 279640000);
qe.Criteria.AddCondition("new_province", ConditionOperator.Equal, 100000018);
qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
//qe.Criteria.AddCondition("ownerid", ConditionOperator.In, "6DEFA813-56F9-E411-80CC-00155D0B0C2D", "CBDD653B-57F9-E411-80CC-00155D0B0C2D", "6CE879FD-56F9-E411-80CC-00155D0B0C2D");
EntityCollection response = service.RetrieveMultiple(qe);
foreach (Entity account in response.Entities)
{
PhoneCall phonecall = new PhoneCall
{
// ToDo: How can I add a phone call activity and assign it to the above created Accounts, also to splitting them amongst 4 users in the system
};
}
}
You can use following code:
Guid[] users = new Guid[] { <id1>, <id2>, <id3>, <id4>};
var counter = 0;
foreach (Entity account in response.Entities)
{
PhoneCall phone = new PhoneCall();
ActivityParty _from = new ActivityParty();
phone.OwnerId =
_from.PartyId = new EntityReference("systemuser", users[counter % 4]);
ActivityParty _to = new ActivityParty();
_to.PartyId = account.ToEntityReference();
phone.From = new ActivityParty[] { _from };
phone.DirectionCode = true;
phone.Subject = "phone call trial";
phone.To = new ActivityParty[] { _to };
service.Create(phone);
counter++;
}
Just curious - have you tried to search an answer using search engine? I found an answer on the first page - https://www.google.com.ua/?gfe_rd=cr&ei=7I1hVvX4PI2u8we4v6iQAw#q=Microsoft+CRM+2011+Create+PhoneCall+C%23

Insert an image into a .docx file

I am developing a program that has the feature to dynamically create DocX files. As the title suggests, I am having a problem inserting images into a DocX file. One of the issues, as I see it, is that I am using C# 2.0. (When answering this question, I would like to stress that I do not wish to switch to C# 3.0, so please do not try to persuade me.)
I have taken a look at the MSDN article at http://msdn.microsoft.com/en-us/library/office/bb497430.aspx, but when I converted the C# 3.0 code that MSDN uses to C# 2.0, I get a document that does not open, and it gives me the error: "The file Testing.docx cannot be opened because there are problems with the contents," and "No error detail available."
Here is my code:
ImagePart ip_Part;
WordprocessingDocument wpd_Doc = WordprocessingDocument.Create("C:\\Convert\\Testing.docx", WordprocessingDocumentType.Document);
public Testing()
{
wpd_Doc.AddMainDocumentPart();
wpd_Doc.MainDocumentPart.Document = new Document();
wpd_Doc.MainDocumentPart.Document.Body = new Body();
ip_Part = wpd_Doc.MainDocumentPart.AddImagePart(ImagePartType.Png);
System.IO.FileStream fs_Stream = new System.IO.FileStream("image.png", System.IO.FileMode.Open);
ip_Part.FeedData(fs_Stream);
AddImageToBody("image.png", wpd_Doc.MainDocumentPart.GetIdOfPart(ip_Part));
AppendText("Here is a test bulleted list:");
wpd_Doc.MainDocumentPart.Document.Save();
//Close the document.
wpd_Doc.Close();
}
private void AddImageToBody(string s_ImagePath, string s_RelationshipId)
{
//OpenXmlElement oxe_Element = new Numbering();
Drawing d_Drawing = new Drawing();
DrawWord.Inline i_Inline = new DrawWord.Inline();
DrawWord.Extent e_Extent = new DrawWord.Extent();
e_Extent.Cx = 600075; //63px / 96dpi * 914400
e_Extent.Cy = 600075; //63px / 96dpi * 914400
i_Inline.Extent = e_Extent;
DrawWord.DocProperties dp_Prop = new DrawWord.DocProperties();
//dp_Prop.Id = uint.Parse(System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString());
dp_Prop.Id = 1;
dp_Prop.Name = "Picture 1";
dp_Prop.Description = "An automated image.";
i_Inline.DocProperties = dp_Prop;
DrawWord.NonVisualGraphicFrameDrawingProperties nvgfdp_Prop = new DrawWord.NonVisualGraphicFrameDrawingProperties();
Draw.GraphicFrameLocks gfl_Locks = new Draw.GraphicFrameLocks();
gfl_Locks.NoChangeAspect = true;
nvgfdp_Prop.GraphicFrameLocks = gfl_Locks;
i_Inline.NonVisualGraphicFrameDrawingProperties = nvgfdp_Prop;
Draw.Graphic g_Graphic = new Draw.Graphic();
Draw.GraphicData gd_Data = new DocumentFormat.OpenXml.Drawing.GraphicData();
gd_Data.Uri = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
DrawPic.Picture p_Pic = new DrawPic.Picture();
DrawPic.NonVisualPictureProperties nvpp_Prop = new DrawPic.NonVisualPictureProperties();
DrawPic.NonVisualDrawingProperties nvdp_Prop = new DrawPic.NonVisualDrawingProperties();
nvdp_Prop.Id = uint.Parse(System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString());
//nvdp_Prop.Name = s_ImagePath;
nvdp_Prop.Name = "New_Image.png";
nvpp_Prop.NonVisualDrawingProperties = nvdp_Prop;
DrawPic.NonVisualPictureDrawingProperties nvpdp_Prop = new DrawPic.NonVisualPictureDrawingProperties();
nvpp_Prop.NonVisualPictureDrawingProperties = nvpdp_Prop;
p_Pic.NonVisualPictureProperties = nvpp_Prop;
DrawPic.BlipFill bf_Fill = new DrawPic.BlipFill();
Draw.Blip b_Blip = new Draw.Blip();
Draw.ExtensionList el_List = new Draw.ExtensionList();
Draw.BlipExtension be_Extension = new Draw.BlipExtension();
be_Extension.Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}";
el_List.Append(be_Extension);
b_Blip.Append(el_List);
b_Blip.Embed = s_RelationshipId;
b_Blip.CompressionState = Draw.BlipCompressionValues.Print;
bf_Fill.Blip = b_Blip;
Draw.Stretch s_Stretch = new Draw.Stretch();
Draw.FillRectangle fr_Rect = new Draw.FillRectangle();
s_Stretch.FillRectangle = fr_Rect;
bf_Fill.Append(s_Stretch);
p_Pic.BlipFill = bf_Fill;
DrawPic.ShapeProperties sp_Prop = new DrawPic.ShapeProperties();
Draw.Transform2D t2d_Transform = new Draw.Transform2D();
Draw.Offset o_Offset = new Draw.Offset();
o_Offset.X = 0;
o_Offset.Y = 0;
t2d_Transform.Offset = o_Offset;
Draw.Extents e_Extents = new Draw.Extents();
e_Extents.Cx = 600075; //63px / 96dpi * 914400
e_Extents.Cy = 600075; //63px / 96dpi * 914400
t2d_Transform.Extents = e_Extents;
sp_Prop.Transform2D = t2d_Transform;
Draw.PresetGeometry pg_Geom = new Draw.PresetGeometry();
Draw.AdjustValueList avl_List = new Draw.AdjustValueList();
pg_Geom.AdjustValueList = avl_List;
pg_Geom.Preset = Draw.ShapeTypeValues.Rectangle;
sp_Prop.Append(pg_Geom);
p_Pic.ShapeProperties = sp_Prop;
gd_Data.Append(p_Pic);
g_Graphic.GraphicData = gd_Data;
i_Inline.Graphic = g_Graphic;
d_Drawing.Inline = i_Inline;
//oxe_Element.Append(d_Drawing);
//Run r_Run = new Run(d_Drawing);
wpd_Doc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(d_Drawing)));
}
(The variable names are bad, but this was just a test program, so I did not spend too much time. Also, I have the lines spaced to mimic the Xml format that MSDN had in its example. If I could use the C# 3.0 syntax, I would, but I am using Visual Studio 2005.)
I have found the answer. Surprisingly, I did not find this webpage--because it was some Google pages down with some odd keyword searching--that completely worked: http://blog.stuartwhiteford.com/?p=33. Though it is written with Collection Initializations, I was able to change them to fit C# 2.0 standards.

ebay GetOrders API using OutputSelector and SortOrder - .Net SDK

I am using ebay .Net SDK. Everything is working fine except following requirements:
Using of OutputSelector to boost performance
Unable to use SortingOrder, while showing records.
Total income/amount sold for specified time range i.e. Total amount across all calls of the pagination without looping through pages and aggregating it manually.
Here is the code which I am using:
var apicall = new GetOrdersCall(context);
//apicall.ApiRequest.OutputSelector = new StringCollection(new String[] { "Order.OrderID", "Order.Total" });
apicall.ApiRequest.Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
};
var fltr = new TimeFilter(Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"), Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"));
var statusCodeType = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]);
var orders = apicall.GetOrders(fltr, TradingRoleCodeType.Seller, statusCodeType);
Please assist me how to use these 3 functionality as well.
After much efforts I got the way for it:
var request = new GetOrdersRequestType
{
//OutputSelector = new StringCollection {"OrderID","Total"},
CreateTimeFrom = Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"),
CreateTimeTo = Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"),
OrderStatus = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]),
OrderRole = TradingRoleCodeType.Seller,
Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
}
};
var apicall = new GetOrdersCall(context)
{
ApiRequest = request,
OutputSelector =
new string[]
{
"OrderID", "Total", "PaidTime", "eBayPaymentStatus",
"PaymentMethod", "Title", "PageNumber", "PaginationResult.TotalNumberOfPages"
}
};
apicall.Execute();
var orders = apicall.ApiResponse.OrderArray;

Categories

Resources