Is using CAPICOM a requirement ? It will work but is has a couple of really annoying downside and, if you don't /have/ to use it, you'd be better using System.Security.Cryptography.
Anyway: To use CAPICOM, you must first add a reference to it in your project. Then:
CAPICOM.SignedData signeddata = new CAPICOM.SignedData();
FileStream file = File.Open(tbSourceFile.Text, FileMode.Open);
byte[] Content = new byte[(int)file.Length];
file.Read(Content, 0, (int)file.Length);
file.Close();
StringWriter sw = new StringWriter();
sw.Write(Content);
signeddata.Content = sw.ToString();
IStore store = new CAPICOM.Store();
store.Open(CAPICOM.CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE, "MY", CAPICOM.CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY | CAPICOM.CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY);
ICertificates2 certificates = (ICertificates2)store.Certificates;
certificates = certificates.Find(CAPICOM_CERTIFICATE_FIND_TYPE.CAPICOM_CERTIFICATE_FIND_KEY_USAGE, CAPICOM_KEY_USAGE.CAPICOM_DIGITAL_SIGNATURE_KEY_USAGE, true);
if (certificates.Count > 0)
{
certificates = certificates.Select();
}
if (certificates.Count > 0)
{
ISigner2 signers = new CAPICOM.Signer();
signers.Certificate = certificates[1];
tbSignatureBlock.Text = signeddata.Sign(signers, true);
}