I am trying to get the contact's avatar image.
using Microsoft.Office.Interop.Outlook;
public sealed class OutlookAvatarFetcher
{
private static void FetchAvatars()
{
var outlook = new Application();
var folder = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts);
var items = folder.Items;
for (var i = 0; i < items.Count; ++i)
{
var contact = items[i + 1] as ContactItem;
if (contact == null)
continue;
if (contact.HasPicture)
{
// TODO store the picture somehow.
}
}
}
}
But unfortunately I can't find a picture accessor.
You can use the attachments property of the ContactItem:
contact.Attachments["ContactPicture.jpg"]
If you want to save the file to disk, for example, you could do something like this:
contact.Attachments["ContactPicture.jpg"].SaveAsFile(#"{some_path}\ContactPicture.jpg")
Do you mean the picture that comes from Facebook or LinkedIn?
You cannot access it - MS did not provide any API to do that for legal purposes. Remember, that data comes from a third party service, and quite a few lawyers are involved in cases like this.
Related
I am trying to get the full contents of my modules From Zoho to our local Server. The deluge code does work as it returns to me the data which is being sent via the API. However, once it reaches the API, it is null. Any idea?
Below is the deluge code:
// Create a map that holds the values of the new contact that needs to be created
evaluation_info = Map();
evaluation_info.put("BulkData",zoho.crm.getRecords("Publishers"));
data = Map();
data.put(evaluation_info);
response = invokeurl
[
url :"https://zohoapi.xxxxx.com/publisher/publish"
type :POST
parameters:data
connection:"zohowebapi"
];
info data; (data returns all the data from publishers)
Here is my ASP.NET core restful API. It does ping it and create the file but the content of the file is null.
Route("[controller]")]
[ApiController]
public class PublisherController : ControllerBase
{
[HttpGet("[action]"), HttpPost("[action]")]
public void Publish(string data)
{
(it's already null when it comes here. why?)
string JSONresult = JsonConvert.SerializeObject(data);
string path = #"C:\storage\journalytics_evaluationsv2.json";
using (var file = new StreamWriter(path, true))
{
file.WriteLine(JSONresult.ToString());
file.Close();
}
}
}
}
What am I missing? Thank you
After contacting Zoho support, the solution he offered was to loop through the data in order to get all the contents from a module (if they are more than 200 records. With the solution provided, one doesn't really need the deluge code anymore as long as you have the ZOHO api set to your account in code. This was my final solution. This solution is not scalable at all. It's best to work with the BULK CSV.
// Our own ZohoAPI which lets us connect and authenticate etc. Yours may look slightly different
ZohoApi zohoApi = new ZohoApi();
zohoApi.Initialize();
ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
var allMedicalJournals = new List<ZCRMRecord>();
for (int i = 1; i <= 30; i++)
{
List<ZCRMRecord> accountAccessRecords2 =
restClient.GetModuleInstance("Journals").SearchByCriteria("Tag:equals:MedicalSet", i, 200).BulkData.ToList();
foreach (var newData in accountAccessRecords2)
allMedicalJournals.Add(newData);
}
I'd like to add a new tag ("LV95_original") to an image ( JPG, PNG or something else..)
How can I add a custom EXIF tag to a image?
This is what I've tried so far:
using (var file = Image.FromFile(path))
{
PropertyItem propItem = file.PropertyItems[0];
propItem.Type = 2;
propItem.Value = System.Text.Encoding.UTF8.GetBytes(item.ToString() + "\0");
propItem.Len = propItem.Value.Length;
file.SetPropertyItem(propItem);
}
This is what I've researched:
Add custom attributes: This uses something different
SetPropert: This updates a property, I need to add a new one
Add EXIF info: This updates standard tags
Add new tags: This is what I've tried, didn work
Actually the link you are using is working just fine. You did however miss one important point:
You should set the Id to a suitable value; 0x9286 is 'UserComment' and certainly a good one to play with.
You can make up new Ids of your own but Exif viewers may not pick those up..
Also: You should either grab a valid PropertyItem from a known file! That is one you are sure that it has one. Or, if you are sure your target file does have ar least one PropertyItem you can go ahead and use it as a proptotype for the one you want to add, but you still need to change its Id.
public Form1()
{
InitializeComponent();
img0 = Image.FromFile(aDummyFileWithPropertyIDs);
}
Image img0 = null;
private void button1_Click(object sender, EventArgs e)
{
PropertyItem propItem = img0.PropertyItems[0];
using (var file = Image.FromFile(yourTargetFile))
{
propItem.Id = 0x9286; // this is called 'UserComment'
propItem.Type = 2;
propItem.Value = System.Text.Encoding.UTF8.GetBytes(textBox1.Text + "\0");
propItem.Len = propItem.Value.Length;
file.SetPropertyItem(propItem);
// now let's see if it is there:
PropertyItem propItem1 = file.PropertyItems[file.PropertyItems.Count()-1];
file.Save(newFileName);
}
}
There is are lists of IDs to be found from here.
Note that you will need to save to a new file since you are still holding onto the old one..
You can retrieve by their ID:
PropertyItem getPropertyItemByID(Image img, int Id)
{
return img.PropertyItems.Select(x => x).FirstOrDefault(x => x.Id == Id);
}
and get at string values like this:
PropertyItem pi = getPropertyItemByID(file, 0x9999); // ! A fantasy Id for testing!
if (pi != null)
{
Console.WriteLine( System.Text.Encoding.Default.GetString(pi.Value));
}
I am creating a Plugin for CRM Which sets the Title of the page as First Name for Account Entity.
The desired result I have achieved the same by writing a javascript function on formload Event
in CRM.
Following is the code
var titlename = Xrm.Page.data.entity.attributes.get("firstname").getValue();
var titleSpan = document.getElementById('form_title_div');
if(titleSpan) {
for(var i = 0;i < titleSpan.children.length;i++) {
if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {
titleSpan.children[i].innerText = titlename;
}
}
}
But my client don't want any javascript code instead he wants it thru Plugin.
I have written a plugin but don't know how to get and set the Title of the page.
Plugin project is a C# Class library.
Code is below for Plugin
Basically I want C# code for commented(Javascipt) Lines
using (var crm = new XrmServiceContext(service))
{
var account = crm.ContactSet.Where(c => c.AccountId == id).First();
var titlename = contact.Crmp_Firstname.ToString();
//var titleSpan = document.getElementById('form_title_div');
//if(titleSpan) {
//for(var i = 0;i < titleSpan.children.length;i++) {
//if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {
//titleSpan.children[i].innerText = titlename;
//}
//}
//}
}
Thanks in advance for any help
It is not possible to modify the title of an account form by a plugin.
This because plugins act server side, instead JavaScript (and your account form) is executed client side.
CRM doesn't store the title of the account, but generates it at runtime.
Suppose I have a program which allows a user to upload any kind of file. Along with getting generic information such as file type and file size, I would like to attempt to grab any extra information (such as document properties like author, last revised, etc) that may be transported along with the document.
Since I don't have any knowledge about the incoming document/file ahead of time, I can't simply use classes that are specific to, say Microsoft Office docs. I need to do this generically and then construct a dynamic object or dictionary to hold any found key/value results.
Is this possible? If so, how? Any help is appreciated!
I found a few answers on StackOverflow for this, but none gave me a nice, clean dictionary of document properties. Here is what I finally came up with and it seems to be working nicely (you will need to reference "Microsoft Shell Controls and Automation" from the COM folder and add using Shell32; to your code:
public static Dictionary<string,string> GetDocumentMetadata(string fileName)
{
var properties = new Dictionary<string,string>();
var arrHeaders = new List<string>();
var shell = new Shell();
var objFolder = shell.NameSpace(HttpContext.Current.Server.MapPath("~/RawFiles"));
var file = objFolder.ParseName(fileName);
for (var i = 0; i < short.MaxValue; i++)
{
var header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
}
for (var i = 0; i < arrHeaders.Count; i++)
{
var value = objFolder.GetDetailsOf(file, i);
if (!String.IsNullOrEmpty(value))
{
properties.Add(arrHeaders[i], value);
}
}
return properties;
}
I am attempting to write code that reads each item from the user's Windows Media Player library. This code works for the majority of users, but for some users, getAll() will return an empty list when they clearly have hundreds or thousands of items in their Windows Media Player library.
var player = new WindowsMediaPlayer();
var collection = player.mediaCollection;
var list = collection.getAll();
int total = list.count;
I am referencing the WMPLib namespace by adding a COM reference to wmp.dll. My application ships with Interop.WMPLib.dll. How would some users' machines be configured in such a way that they run Windows Media Player with many songs in their library, but WMPLib fails to function correctly? Furthermore, what workarounds exist to reliably read the user's Windows Media Player library in all cases?
Try this snippet and see if it works for you.
public List<MusicEntry> GetMusicLibrary()
{
List<MusicEntry> entries;
IWMPPlaylist mediaList = null;
IWMPMedia mediaItem;
try
{
// get the full audio media list
mediaList = media.getByAttribute("MediaType", "Audio");
entries = new List<MusicEntry>(mediaList.count);
for (int i = 0; i < mediaList.count; i++)
{
mediaItem = mediaList.get_Item(i);
// create the new entry and populate its properties
entry = new MusicEntry()
{
Title = GetTitle(mediaItem),
Album = GetAlbum(mediaItem),
Artist = GetArtist(mediaItem),
TrackNumber = GetTrackNumber(mediaItem),
Rating = GetRating(mediaItem),
FileType = GetFileType(mediaItem)
};
entries.Add(entry);
}
}
finally
{
// make sure we clean up as this is COM
if (mediaList != null)
{
mediaList.clear();
}
}
return entries;
}
For more information refer to this excellent article on Code Project.
http://www.codeproject.com/Articles/36338/Export-Windows-Media-Player-Music-Metadata-to-XML