Cyberiafreak

"Fortunate are those who take the first steps.” ― Paulo Coelho

How to use the Outlook object model to retrieve all recurring appointments

You have to set ‘oItems.IncludeRecurrences = True’ if you are trying to get all the recurring calendar items in VBA-Outlook.

http://support.microsoft.com/kb/201101/en-us

http://blogs.msdn.com/b/waltwa/archive/2007/03/14/finding-appointments-within-a-specific-timeframe.aspx

Advertisements

April 30, 2014 Posted by | Uncategorized | Leave a comment

How to use the same keyset for strongname signing as well as for manifest and/or Authenticode signing.

Strong name signing requires KeySpec=2 (AT_SIGNATURE). Similar issue was blogged for VS2005  http://blogs.msdn.com/b/andrekl/archive/2008/01/08/strong-name-signing-in-visual-studio-2005-requires-keyspec-2-at-signature.aspx and that still holds true for VS2010. The certificate has KeySpec=1 (AT_EXCHNAGE) and worked around by modifying the certificate to have KeySpeck=1. Steps below helps you to successfully sign the project

1. Using the “Certifiates” MMC export the existing keyset (KeySpec=1) to a PFX file.

2. Delete the existing certificate from the crypto store (using the MMC).

3. Open a CMD prompt.

4. import the PFX file using this command:certutil -importPFX -user <pfxfilename> AT_SIGNATURE

5. Enter the passphrase for the pfx when prompted.

6. You now should have a keyset/Cert with KeySpec=2. If needed you can now export this into another PFX file using the MMC again.

7. Use the new .pfx in the Visual Studio to sign the executable

April 30, 2014 Posted by | Uncategorized | , , | Leave a comment

Profman2.exe – MAPI Profile Manager v2.0

Profman2.exe is a self-extracting achieve that contains a sample program demonstrating how to use the MAPI interfaces and methods that pertain to the manipulation and creation of MAPI profiles.

Here is a list of its functionality:

  • Create a new blank profile.
  • Add services to a profile.
  • Delete services from a profile.
  • List the services in a profile.
  • Add providers to a service.
  • Delete providers from a service.
  • List the providers in a service.
  • List the available properties of a service (even ones that are normally inaccessible).
  • List the available properties of a provider (even ones that are normally inaccessible).
  • Outlook 2000 Compliant (reads proper location of MAPISVC.inf file)

download @ http://support.microsoft.com/kb/228736

April 18, 2014 Posted by | Uncategorized | | Leave a comment

From training-links for later reading { O365 apps, Office PIA, XL, VSTO }

O365 web apps development
1) The Office 365 platform —new opportunities for developers
http://blogs.office.com/2014/03/03/create-apps-for-office-365/

2) Here is a Video of the possibilities :
http://www.youtube.com/watch?v=qryRH5xXyJk&feature=player_embedded

3) MSDN article we might need to be aware of -Office 365 APIs Preview
http://msdn.microsoft.com/en-us/library/office/dn605892.aspx

4) How to: Add Office 365 APIs to a Visual Studio project
http://msdn.microsoft.com/en-us/library/office/dn605899.aspx

UDF
5) What is UDF – http://blogs.msdn.com/b/frice/archive/2004/06/11/153891.aspx

6) UDF using .NET – http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/writing-user-defined-functions-for-excel-in-net.aspx

7) http://msdn.microsoft.com/en-us/library/ms173189(v=vs.80).aspx

8) Automation Add-ins section – http://support.microsoft.com/kb/291392

XLL
9) What is XLL – An XLL is an add-in for Microsoft Excel that you can build with any compiler that supports building DLLs (dynamic link libraries).
10) Download XLL SDK from – http://go.microsoft.com/fwlink/?LinkID=251082&clcid=0x409

11) http://blogs.msdn.com/b/andreww/archive/2007/12/09/building-an-excel-xll-in-c-c-with-vs-2008.aspx

12) http://msdn.microsoft.com/en-us/library/office/bb687861(v=office.15).aspx

13) http://support.microsoft.com/kb/178474

 

Excel
14) Understanding the Excel Object Model from a .NET Developer’s Perspective
http://msdn.microsoft.com/en-us/library/office/aa168292(v=office.11).aspx

15) How to automate Microsoft Excel from Microsoft Visual C#.NET
http://support.microsoft.com/kb/302084

16) How to transfer data to an Excel workbook by using Visual Basic .NET
http://support.microsoft.com/kb/306022

17) How to automate Excel from Visual Basic .NET to fill or to obtain data in a range by using arrays
http://support.microsoft.com/kb/302094

 

Office PIA
18) http://msdn.microsoft.com/en-us/library/15s06t57(v=vs.110).aspx

19) Primary Interop Assemblies Concept – http://msdn.microsoft.com/en-us/library/aax7sdch.aspx

20) http://msdn.microsoft.com/en-us/library/aa302338.aspx

21) Better eventing support in CLR 4.0 using NOPIA support
http://blogs.msdn.com/b/mshneer/archive/2008/10/28/better-eventing-support-in-clr-4-0-using-nopia-support.aspx

22) How to: Install Office Primary Interop Assemblies – http://msdn.microsoft.com/en-us/library/kh3965hw(v=VS.90).aspx

 

VSTO

23) Adding custom task pane
http://social.msdn.microsoft.com/Forums/vstudio/en-US/3316853c-4cec-4cf5-8cf7-5fe6f3cd1bfe/adding-custom-task-pane?forum=vsto

24) How to: Attach Managed Code Extensions to Documents (2007 System)
http://msdn.microsoft.com/en-us/library/bb772091(v=vs.90).aspx

25) Memory leak (When you automate a Off app from .NET, the Office application does not quit when you call the Quit method)
http://support.microsoft.com/kb/317109

April 18, 2014 Posted by | Uncategorized | | Leave a comment

Office server side automation is not supported- famous KB 257757

There is no surprise still developers tend to code some kind of office automation on server without knowing that is not supported by us.
Recently I have seen a case where the developer is creating an excel pivot charts in server(automation) using SQL Server, DTS along with some programming with C#.net. It was working for him but all sudden it broke after migrating to latest server OS.
Here is the famous KB article which we keep sharing with dev’s and also famously referred in MS as “2 5 7 7 5 7” which talks about why this is not supported. More at; 257757 KB here – http://support.microsoft.com/kb/257757

 

April 17, 2014 Posted by | Uncategorized | | Leave a comment

How to use EWS API for reading SMIME email message

What is SMIME – http://technet.microsoft.com/en-us/library/aa995740(v=exchg.65).aspx 

class Program
{
static ExchangeService exService;

static void Main(string[] args)
{
try
{
exService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
exService.UseDefaultCredentials = true;
exService.AutodiscoverUrl(“user@Contoso.com”, RedirectionCallback);

Console.WriteLine(“Connected(Autodiscovered EWS Endpoint)- ” + exService.Url);

//find the trace log dumped in debug\log.txt
exService.TraceEnabled = true;
exService.TraceListener = new TraceListener();
exService.TraceEnablePrettyPrinting = true;

Console.WriteLine(“Getting inbox items..”);
byte[] data = GetInboxMailItems();

if (data == null)
{
Console.WriteLine(“No Mails retreived “);
Console.ReadKey();
return;
}
//
byte[] resultObject= DecryptToFile(data);

if(resultObject==null)
{
Console.WriteLine(“No object retrieved from Decrypt. somthing wrong in this method”);

}
else
{
string uniqueFname = Path.GetRandomFileName()+”.eml”;
Console.WriteLine(@”Decrypted EML file dumped here — c:\temp\” + uniqueFname);

//Find the decrypted file here
//Load this file in Outlook for testing.
File.WriteAllBytes(@”c:\temp\” + uniqueFname, resultObject);
}

//write the decrypted content to a file – mail item .eml
Console.WriteLine(“Press any key to exit..”);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(“Error while initializing..” + ex.ToString());
}
}

/// <summary>
///
/// </summary>
private static byte[] GetInboxMailItems()
{
byte[] data = null;

//Get inbox unread mails (have a mail ready for decrypt which is signed & decrypt)
Folder inbox = Folder.Bind(exService, WellKnownFolderName.Inbox);
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));

ItemView view = new ItemView(1);

FindItemsResults<Item> findResults = exService.FindItems(WellKnownFolderName.Inbox, sf, view);

//Have atleast 1 unread ‘encrypted,signed’ mail for this testing
if (findResults.TotalCount == 0)
{
return data;
Console.WriteLine(“No Mails retreived”);
}

//Loop through the items and do whatever is required.
foreach (Item item in findResults)
{
//Load the mail item
PropertySet ps = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments);
item.Load(ps);

foreach (Microsoft.Exchange.WebServices.Data.Attachment attach in item.Attachments)
{
// find the encrypted mails attachment- in general body and any mail content for encrypted mail would be bundled as smime.p7m file in mailstore
if (attach.Name == “smime.p7m”)
{
Console.WriteLine(“Process smime.p7m file”);
FileAttachment fileAttachment = (FileAttachment)attach;
MemoryStream stream = new MemoryStream();
fileAttachment.Load(stream);
StreamReader stReader = new StreamReader(stream);
stream.Seek(0, SeekOrigin.Begin);
data = stream.GetBuffer();

return data;
}
}
}
return data;
}

/// <summary>
///
/// </summary>
/// <param name=”data”></param>
private static byte[] DecryptToFile(byte[] data)
{
byte[] resultObject = null;

try
{
EnvelopedCms envelopObj = new EnvelopedCms();
envelopObj.Decode(data);

Console.WriteLine(“Encryption Algorithm: Name={0}”, envelopObj.ContentEncryptionAlgorithm.Oid.FriendlyName);
Console.WriteLine(“Key length={0}”, envelopObj.ContentEncryptionAlgorithm.KeyLength);
Console.WriteLine(“Recipients ({0})”, envelopObj.RecipientInfos.Count);

foreach (RecipientInfo r in envelopObj.RecipientInfos)
{
Console.WriteLine(” Encrypted key={0}”, BitConverter.ToString(r.EncryptedKey));
Console.WriteLine(” Encryption alg={0}”, r.KeyEncryptionAlgorithm.Oid.FriendlyName);

if (r.RecipientIdentifier.Type == SubjectIdentifierType.IssuerAndSerialNumber)
{
X509IssuerSerial xi = (X509IssuerSerial)r.RecipientIdentifier.Value;
Console.WriteLine(” Issuer={0}”, xi.IssuerName);
Console.WriteLine(” SerialNumber={0}”, xi.SerialNumber);
}
else
{
Console.WriteLine(” SubjectKeyInfo={0}”, r.RecipientIdentifier.Value);
}
}

Console.WriteLine(“Certificates ({0})”, envelopObj.Certificates.Count);

foreach (X509Certificate2 cert in envelopObj.Certificates)
{
Console.WriteLine(“Subject={0}”, cert.SubjectName);
}

Console.WriteLine(“Unprotected Attributes ({0})”, envelopObj.UnprotectedAttributes.Count);

foreach (CryptographicAttributeObject obj in envelopObj.UnprotectedAttributes)
{
Console.WriteLine(obj.Oid.FriendlyName);
}

envelopObj.Decrypt();
Console.WriteLine(“Success. Decrypted… !!”);
resultObject = envelopObj.ContentInfo.Content;

return resultObject; ;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return resultObject;
}

/// <summary>
///
/// </summary>
/// <param name=”url”></param>
/// <returns></returns>
static bool RedirectionCallback(string url)
{
// Return true if the URL is an HTTPS URL.
return url.ToLower().StartsWith(“https://&#8221;);
}
}

/// <summary>
///
/// </summary>
public class TraceListener : ITraceListener
{
#region ITraceListener Members

public void Trace(string traceType, string traceMessage)
{
CreateXMLTextFile(traceType + ” — ” + traceMessage.ToString());
}

#endregion

private void CreateXMLTextFile(string traceContent)
{
string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
strPath = strPath + “\\Log.txt”;
System.IO.FileStream fs;
if (System.IO.File.Exists(strPath) == false)
{
fs = System.IO.File.Create(strPath);
}
else
{
fs = System.IO.File.OpenWrite(strPath);
}

fs.Close();

// Create an instance of StreamWriter to write text to a file.
System.IO.StreamWriter sw = System.IO.File.AppendText(strPath);
sw.WriteLine(System.DateTime.Now.ToString() + “: ” + traceContent);
sw.Close();

}
}

April 15, 2014 Posted by | Uncategorized | , , | 13 Comments

How to convert Hex to Base64 in C#

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that is designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML.

//Convert Hex to Base64
static void Main(string[] args)
{
string hexstr = “040000008200E00074C5B7101A82E0080000000622029301EB4592B71528F44A48D7”;
byte[] data = ConvertFromStringToHex(hexstr);
string base64 = Convert.ToBase64String(data);

Console.WriteLine(base64);
}

public static byte[] ConvertFromStringToHex(string inputHex)
{
inputHex = inputHex.Replace(“-“, “”);

byte[] resultantArray = new byte[inputHex.Length / 2];
for (int i = 0; i < resultantArray.Length; i++)
{
resultantArray[i] = Convert.ToByte(inputHex.Substring(i * 2, 2), 16);
}
return resultantArray;
}

April 15, 2014 Posted by | Uncategorized | | Leave a comment

   

%d bloggers like this: