Show Outlook contact card in WPF app - c#

I am working on a WPF app (written in C#) that searches and serves data from the active directory. Searching for a user will fetch all phone numbers for the user and display on the app window.
How can I open the outlook contact card by the click of some icon or the username or something?

The Outlook Contact Card is part of Microsoft Outlook and (as far as I know) not a public control, so you can not simply 'open' it unless you are creating an Outlook add-in.
Using the Active Directory's information you could recreate it.

By Outlook Contact Card I assume you mean a vCard (*.VCF file). It is actually nothing more than a text file. You can easily recreate it. For example:
Create a StringBuilder instance and write the contents of the .VCF file to it.
var vcf = new StringBuilder();
vcf.Append("TITLE:" + contact.Title + System.Environment.NewLine);
//...
Afterwards you can save it to a file.
var filename = #"C:\mycontact.vcf";
File.WriteAllText(filename, vcf.ToString());
Most properties are easy to figure out.
A small example:
BEGIN:VCARD
FN:Mr. John Smith
TITLE:Developer
ORG:Microsoft
BDAY:1979-12-10
VERSION:2.1
END:VCARD
If you want to include an image you have to base 64 encode it.
If you open this newly created file:
Process.Start(#"C:\mycontact.vcf");
Then it should be opened by the application that is configured by default to handle this file extension.
Wikipedia contains more information about the contents of a vCard:
http://en.wikipedia.org/wiki/VCard

It seems that outlook is using a Lync Feature.
Even if not exactly the Same you can use the Lync SDK in your wpf app if you use Lync.
http://msdn.microsoft.com/en-us/uc14trainingcourse_2l_topic2#_Toc273951814

Related

How to create SQL Server data backup file in Outlook Compatible format by C# code

I want to take backups of all emails from SQL Server database and need to create it's backup file using C# code in outlook compatible format. So that emails can be restored in outlook software.
Please help
Till now we have created one desktop application and we have table containing emails which has some custom fields also as per our need.
We have done some exploration on it and found given below links -
Can I read an Outlook (2003/2007) PST file in C#?
http://www.c-sharpcorner.com/article/outlook-integration-in-C-Sharp/
https://www.add-in-express.com/creating-addins-blog/2013/12/20/create-outlook-files/
Can I read an Outlook (2003/2007) PST file in C#?
My problem is that we have some custom fields in database so how they will get stored in outlook data files
Email table structure is given below -
You can use Outlook Object Model and its Namespace.AddStore/AddStoreEx methods to add new or existing PST file to a profile and then (given the returned Store object) populate it with folders and emails. To store custom properties, use MailItem.UserProperties collection.
Note however that OOM will not work in a service - you'd need Extended MAPI (C++ or Delphi) or Redemption (I am its author - any language) for that. Creating items in the sent state can also be a challenge. If using Redemption is an option, it exposes RDOSession.LogonPstStore method that create (and deletes) a temporary profile configured to work with the specified PST file. It can be used i na service. No existing Outlook profiles are affected.
Redemption.RDOSession session = new Redemption.RDOSession();
Redemption.RDOPstStore store = session.LogonPstStore(PstFileName);
Redemption.RDOFolder folder = store.IPMRootFolder.Folders.Add("Backup folder");
RDOMail item = folder.Items.Add("IPM.Note");
item.Sent = true;
item.Subject = "test";
item.Body = "test body";
item.Recipients.AddEx("The User", "user#domain.demo", "SMTP");
item.UserProperties.Add("My custom prop", olText).Value = "custom prop value";
item.Save();
Your description is still not precise enough.
Do you want to store individual e-mails from outlook into database and eventually get them back as e-mails in Outlook?
Then it looks like you have all you need.
MailItem in Outlook has more-less properties like you in database.
Then conceptually it should look like this:
Enumarate MAPIFolder and for each e-mail store properties inside database and then delete e-mail.
In case of restoring read database record, create new MailItem and add it to folder.
BUT:
I see some problems with field types - i.e. EmailTo nvarchar(100) is far too small.
Additionally you don't have all fields to restore e-mail 1:1.
So i.e. storing msg file could be good option (maybe additionally to data you are retrieving).
Please specify more details then I could also answer in better way.
EDIT:
According to your clarification (still not sure if I understand correctly):
Simpliest way would be to use outlook for this process.
Create in outlook pst folder, create e-mails inside and then backup complete pst file (then you have all in one file) or export individually e-mails to .msg files (then 1 file per e-mail).
Trying to write directly from your application to pst file or to msg file could be very hard since format of those files are not described.
Please precise if you want to use Outlook for this process or not.

Add button and custom functionality to adobe reader

I am working on a WPF 4.5 application which needs to interact with PDFs and I am stuck with an issue as described below:
I have template pdfs stored at a specific location. Based on requirement, a copy of the template pdf is created. This pdf has certain fields including text boxes, dropdowns etc. Some of these fields need to be pre-populated like the dropdown values.
Once it is ready, I need to open it, and let the user complete the form. Once completed, the user saves the file and closes it.
Now I need to read the file and send the updated data to the DB. I was able to do all this using iTextSharp by launching the PDF in a separate process and handling the Exited event. Now, the problem I face is this solution does not work if the user uses the SaveAs option to change the name or location of the opened file.
I thought if it would be possible to disable the Save options and add a button on the form clicking which would automatically save the form and close it at the expected location would be a possible solution.
My questions are:
1) Is it possible to find out using the argument of the Exited event handler to find out the saved file name and location? As soon as the user saves the file with a different name, the title of the reader gets updated with the current file name. So I am assuming that the current process is using the latest file.
2) Is it possible to disable the SaveAs and Save file options and close the file on click of a button in the form, using Adobe SDK (JavaScript or plugin or API)?
3) If I use the Adobe SDK, do all the systems on which the application would be installed need to have a licensed version of the Adobe Acrobat?
If the above options are not possible then we would have to settle with dynamic forms. We wanted to experiment with PDF since it is easy to create, and supports image annotations, for which we might need to develop a separate solution, if the above options are not feasible.
I know this is not a very specific programming question, but I need help in order to be able to figure out which path I can go on to be able to achieve the goal.
Please mark duplicate with the link to the other SO question if it a duplicate since I have not been able to figure out one.
Would appreciate answers, links to other posts on SO that are specific to the questions asked.
Please avoid opinion based answers.
Any help would be appreciated.
Any constructive criticism is also welcome.
There is a heavy-handed way to prevent an Acrobat user from Saving a file. In Acrobat, create a Javascript that executes when "Document Will Save." A script like this causes the application to hang rather than Save the file:
var key = "" + this.getField("Password").value;
if (key != "QWERTY") {
app.alert ("No changes to this PDF are allowed,
so you may not Save it.
You will now have to Force Quit or End Task.");
while (true) {};
}
I am not proud of this, but it does the job. You might want to erase the password field before saving.

C# Windows Service > Render Web Page and Output to PDF

I am at a loss and could use some direction. I have a windows service that performs an Audit on customers. For new customers, I need to create a profile for each one. I already have a ASP.net C# web page that displays a single customer profile for the user:
http://webserver/showprofile.aspx?id=CustomerID
I would like to run some type of loop in the service that would render each new customer's profile and output all of those profiles into a PDF, Word Document, etc. Is there an easy way to do this using the existing Show Profile webpage?
If not, what is the best way to do this in C#? If it requires a component, I would prefer something free to very inexpensive. I currently have licenses for Telerik's complete line of tools if there is something there that can help. The bottom line, this has to be done programmatically as the user will have nothing to do with the generation/export to PDF. They will only access the resulting exported file.
Thanks in advance for your help.
You can use PdfCreator using the following command:
private PDFCreator.clsPDFCreator printer;
printer = new PDFCreator.clsPDFCreator();
printer.cDefaultPrinter = "PDFCreator";
printer.cOptions.UseAutosave = 0;
// Format in which file is to be saved. 0 if for pdf.
printer.cOptions.AutosaveFormat = 0;
printer.cClearCache();
printer.cStart();
foreach(int CustomerId in CustomerIDs)//array of customer ids as an example
{
printer.cPrintURL("http://webserver/showprofile.aspx?id=" + CustomerID.ToString());
}
You can download the software and necessary dll at the following link and look at the examples in the .net folder.
http://sourceforge.net/projects/pdfcreator/

Get Filename of the Current Active Window

I am trying to get the filename of a word document or any other window for that matter while some dialog box like Save as or Open or Print etc. is open. Can anybody give me an example of how to implement this in C#.
Windows API can give you the name of the application which occupies a particular window, but to know what file (or files) are open within that application would require OLE automation or some other API supplied by the application (here winword.exe) itself.

Export all contacts as vcards from Outlook

So, I want to export all my contacts from Outlook as vcards. If I google that, I get a bunch of shareware programs, but I want something free that just works.
If I'm to code it myself, I guess I should use the Microsoft.Office.Interop.Outlook assembly. Has anyone already code to convert ContactItems to vcards?
Edit: I solved it in a completely different way, see answer below, but I have marked dok1.myopenid.com's answer as accepted because it answers my original question.
I solved it in a non-programmatically way:
Selected all contacts in Outlook
Forwarded them as cards to myself
Saved all the attachments (vcards) in a folder, c:\temp
Opened a command prompt and typed the command copy /a *.vcf c:\allcards.vcf which concatenates all vcards into one
For what it's worth - I just came across this thread looking for the same export to individual .VCF files from outlook. I haev 2007 (don't know if that makes a difference) but I selected all contacts and dragged them to a new email message to be added as individual .VCF files. After they were all added, I clicked in the attachments section of the new email, hit CTRL-A to highlight all of them, then left-click-dragged the first (and therefore all of them) to the folder I wanted the individual .VCF files in. A few minutes of Outlook "thinking" about my 400 contacts they were all there!
They sure make it hard to find, don't they? See if this helps.
http://msdn.microsoft.com/en-us/library/aa579624(EXCHG.80).aspx
That includes: The following example uses the CDO Person object to obtain vCard information for a contact.
Dim oPerson As New CDO.Person
Dim strm As New ADODB.Stream
' Assume strURL is a valid URL to a person contact item
oPerson.DataSource.Open strURL
' You can set the ADO Stream object to the returned vCard stream
Set strm = oPerson.GetvCardStream
' Save the stream to a file.
' Note: using adSaveCreateOverwrite may cause an existing
' contact to be overwritten.
strm.SaveToFile "d:\vcard.txt", adSaveCreateOverwrite
' You don't have to set a Stream object,
' just use the Stream methods off GetvCardStream directly
oPerson.GetvCardStream.SaveToFile "d:\vcard.txt", adSaveCreateOverwrite
Yep, the only code sample there is in VB.
Just purchased the X8 and was about to get really really mad when I couldn't easily transfer my contacts...until I started snooping around on the phone.
First, export all your contacts in Outlook to vCards (I found emailing them to yourself is the easiest. If you get an error message "to many attachments..." you can save them from the email in your sent items folder) and copy the vCards to the memory card on your phone.
Second, open your address book on the phone then press the left button on the phone (the button with 4 little squares above it. NOT THE 4 BOXES ON THE SCREEN...THE PHYSICAL BUTTON!).
Third, select "Import/Export" and choose import from memory card. Import all vCard files and you should be golden.
Best of luck...don't ask me any questions because I will not be back to look at any more posts...just passing by trying to figure it out on my own.

Categories