I use EWS to get exchange emails, but how can i get plain text from email body, without html?
Now i use this:
EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text
In the PropertySet of your item you need to set the RequestedBodyType to BodyType.Text. Here's an example:
PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView itemview = new ItemView(1000);
itemview.PropertySet = itempropertyset;
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, "subject:TODO", itemview);
Item item = findResults.FirstOrDefault();
item.Load(itempropertyset);
Console.WriteLine(item.Body);
In powershell:
.........
$message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)
$PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text
$message.Load($PropertySet)
$bodyText= $message.Body.toString()
I had the same issue. All you have to do is set RequestedBodyType property of the property set you are using.
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.Body);
propSet.RequestedBodyType = BodyType.Text;
var email = EmailMessage.Bind(service, item.Id, propSet);
The shortest way to do it is like this:
item.Load(new PropertySet(BasePropertySet.IdOnly, ItemSchema.TextBody, EmailMessageSchema.Body));
This has got the advantage that you get both, text-body and html-body.
you can use
service.LoadPropertiesForItems(findResults, itempropertyset);
to load properties for all items
Related
I've a SharePoint 2010 page with a list. The list has several items and a field named "Department" and must filter items based on user's department value retrieved from user profile.
To do this I've created a feature which upon activation adds UserContextFilterWebPart to the page and makes connection between UserContextFilterWebPart and XsltListViewWebPart. After the feature is activated I can see in the page design mode that connection is established but the list gets empty. Then I open web part's menu, choose "Connections" then "Send Filter Values To" and click "List1". When dialog appears I do nothing but only click "Finish" button and it begins to work fine. Can anybody please explain me why the connection begins to work only if I do that manual extra action? What must be done to fix?
I tried different way when List.Views[0].Query property is set to appropriate CAML query and it also works fine. But I'm told that it's not a good approach because of performance and parallel tasks issues. Is it really bad course of action?
Below is the code for 2 different approaches.
Thanks in advance!
1-s variant with UserContextFilterWebPart:
SPSite Site = new SPSite(URL);
SPWeb Web = Site.OpenWeb();
SPLimitedWebPartManager WPM = Web.GetLimitedWebPartManager(URL, PersonalizationScope.Shared);
XsltListViewWebPart List = WPM.WebParts[0] as XsltListViewWebPart;
UserContextFilterWebPart UCFWP = new UserContextFilterWebPart();
UCFWP.Title = "Current User Filter";
UCFWP.AllowEdit = true;
UCFWP.FilterName = "Current User";
UCFWP.SendEmptyWhenNoValues = true;
UCFWP.AllowClose = true;
UCFWP.ExportMode = WebPartExportMode.All;
UCFWP.AllowConnect = true;
UCFWP.AllowHide = true;
UCFWP.ProfilePropertyName = "Department";
UCFWP.ValueKind = UserContextFilterValueKind.ProfileValue;
UCFWP.ZoneID = "Main";
WPM.AddWebPart(UCFWP, UCFWP.ZoneID, 1);
WPM.SaveChanges(UCFWP);
ConsumerConnectionPointCollection consumerConnections = WPM.GetConsumerConnectionPoints(List);
ConsumerConnectionPoint addConsumerConnPoint = consumerConnections["DFWP Filter Consumer ID"];
ProviderConnectionPointCollection providerConnections = WPM.GetProviderConnectionPoints(UCFWP);
ProviderConnectionPoint addProviderConnPoint = providerConnections["ITransformableFilterValues"];
TransformableFilterValuesToParametersTransformer trans = new TransformableFilterValuesToParametersTransformer();
trans.ConsumerFieldNames = new string[] { "Department" };
trans.ProviderFieldNames = new string[] { "Department" };
SPWebPartConnection newConnection = WPM.SPConnectWebParts(UCFWP, addProviderConnPoint, List, addConsumerConnPoint, trans);
WPM.SPWebPartConnections.Add(newConnection);
2-nd variant with CAML query (intended to be used not in a feature but in a web part):
SPSite Site = new SPSite(URL);
SPWeb Web = Site.OpenWeb();
SPLimitedWebPartManager WPM = Web.GetLimitedWebPartManager(URL, PersonalizationScope.Shared);
XsltListViewWebPart List = WPM.WebParts[0] as XsltListViewWebPart;
SPUser CurrentUser = Web.CurrentUser;
SPServiceContext context = SPServiceContext.GetContext(Site);
UserProfileManager upm = new UserProfileManager(context, false);
UserProfile up = upm.GetUserProfile(CurrentUser.RawSid);
String UserDepartment = up["Department"].Value.ToString();
SPView ListView = Web.Lists["List1"].Views[0];
ListView.Query = "<Where><Eq><FieldRef Name='Department' /><Value Type='Text'>" + UserDepartment + "</Value></Eq></Where>";
ListView.Update();
I had a similar problem of connecting two web parts. I found the answer here: http://kvdlinden.blogspot.dk/2011/02/programmatically-connect-two.html
Note that that post describes how to do it with two XsltListViewWebParts. In order to use it in your case I suggest that you:
Create the connection manually,
Use PowerShell to get a SPLimitedWebPartManager for the page,
Use the manager to iterate through the manager.SPWebPartConnections,
And find the ProviderConnectionPointID for your connection,
Use that ID in the code shown in the post.
Also remember to setup the transformer - you can find this also from the SPWebPartConnections.
Next time you activate your feature you should have a connection equal to the one you made by hand.
I need to find out (programmatically) what term set is used by a certain user profile property, but I can't figure out how to do that. Any ideas are highly appreciated!
Finally, figured it out:
SPSite site = new SPSite(url);
SPServiceContext context = SPServiceContext.GetContext(site);
var userProfileConfigManager = new UserProfileConfigManager(context);
ProfilePropertyManager profilePropertyManager = userProfileConfigManager.ProfilePropertyManager;
CorePropertyManager corePropertyManager = profilePropertyManager.GetCoreProperties();
CoreProperty property = corePropertyManager.GetPropertyByName(propertyName);
TermSet ts = property.TermSet; // DONE!
I am trying to insert new ListItems in a Sharepoint 2010 List already created. The code I'm using is:
ClientContext ctx = new ClientContext("http://bigboss/sites/presidencia");
Web thisWeb = ctx.Web;
ctx.Load(thisWeb);
List processosList = ctx.Web.Lists.GetByTitle("Processos");
ListItemCreationInformation lici = new ListItemCreationInformation();
ListItem liNovoProcesso = processosList.AddItem(lici);
liNovoProcesso["Title"] = processo.Identificador;
liNovoProcesso["IdentificadorProcesso"] = processo.Identificador;
liNovoProcesso["DescricaoProcesso"] = processo.Descricao;
liNovoProcesso["NotasObservacoesProcesso"] = processo.NotasObservacoes;
liNovoProcesso["SituacaoProcesso"] = processo.Situacao;
processosList.Update();
ctx.ExecuteQuery();
This code runs without erros or exceptions, but the list isn't showing the items. I've already tried to change Field names to trigger an error, just to be sure that the code its running, and it throws an error, like expected!
Any tips, please?
thanks,
José Cruz
Are you missing ?
liNovoProcesso.Update();
You should update the ListItem object instead of List.
I have the following code:
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[this.ListName];
SPListItem item = list.Items.Add();
item["linktoAttachment"] = this.SiteAddress + file.Url;
My question is how can I have friendly link text...
like in a classic hyperlink you have
friendly link here
Thanks
YOur LinkToAttachment field Should of Type Url, then you can use the following:
item["linktoAttachment"] = string.Format("{0},{1}", this.SiteAddress + file.Url, "friendly link here");
Another option is:
SPListItem newLink = list.Items.Add();
SPFieldUrlValue value = new SPFieldUrlValue();
value.Description = "friendly link here";
value.Url = this.SiteAddress + file.Url;
newLink["linktoAttachment"] = value;
In my code, I have lines like this:
Builder builder = new Builder();
builder.AddFromFile(gladefile);
FileChooserDialog dialog =
(FileChooserDialog) builder.GetObject("dialog");
FileFilter[] filters = new FileFilter[2];
filters[0] = new FileFilter();
filters[0].Name = "Some filter";
filters[0].AddPattern("*.someextension");
filters[1] = new FileFilter();
filters[1].Name = "All files";
filters[1].AddPattern("*");
foreach (FileFilter filter in filters)
dialog.AddFilter(filter);
dialog.Filter = filters[0];
dialog.SetFilename(defaultFile);
Is there a way to set up these filters in Glade, rather than doing it manually?
It is possible now. The code snippet should probably look something like this:
builder = Gtk.Builder()
builder.add_objects_from_file("***name of glade file****.glade",
("filechooserdialog1", "filefilter1"))
dialog = self.builder.get_object("filechooserdialog1")
filefilter = self.builder.get_object("filefilter1")
dialog.add_filter(filefilter)
No. You can create a file filter object in glade (version 3.6 and up) and add it to the dialog, but since you can't actually set the name or pattern of the file filter, it's fairly useless.