My programs works perfectly with using hotkeys in place to alter text in Microsoft Word, Powerpoint, Excel, and Outlook.
The only problem I have is that the program will not execute unless I either click on it with the mouse or use Alt and Tab to toggle between my program and Microsoft Office programs.
I wish to not use the mouse or use Alt and Tab. I have a keyboard hook script in place to copy the hotkeys, but it will only work if Windows sees my program on top of everything and is active.
I have my program on top of everything, but when going to Microsoft Word (for example), my program is no longer active and Microsoft Word is now active. I would have to go to my program to make it active by clicking on it with my mouse or using Alt and Tab, perform the hotkey and then go back to Microsoft Word with using my mouse to click on it or using Alt and Tab to make it active to use the hotkey that was pressed.
With this, how would I go about and make my program a shared plugin for Microsoft Office, to where when it is running, Microsoft Office will recognize my program?
First of all, you can automate Outlook form other applications. Due to the fact that Outlook is a singleton only one application instance can be run at the same time on the system. So, you may get a running instance from the ROT:
//Get reference to Outlook.Application from the ROT.
oApp = (Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
If there is no Outlook running on the system you may simply create a new one. See C# app automates Outlook (CSAutomateOutlook) for more information.
Here is my code for you to view so you have an idea what I am doing.
Sorry, I tried to put it as a comment, but it was too long.
//MICROSOFT WORD INTEGRATION
try
{
app = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
app.ActiveWindow.Selection.Font.Color = (Microsoft.Office.Interop.Word.WdColor)(changeColor.R + 0x100 * changeColor.G + 0x10000 * changeColor.B);
}
catch (System.Exception excp)
{
}
//MICROSOFT EXCEL INTEGRATION
try
{
xlApp = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
xlBook = xlApp.ActiveWorkbook;
xlSheet = xlBook.ActiveSheet;
Microsoft.Office.Interop.Excel.Range rngSelection = xlApp.Selection as Microsoft.Office.Interop.Excel.Range;
for (var r = 1; r <= rngSelection.Rows.Count; r++)
{
for (var c = 1; c <= rngSelection.Columns.Count; c++)
{
rngSelection[r, c].Font.Color = copyProgramText.SelectionColor;
}
}
}
catch (System.Exception excp)
{
}
//MICROSOFT POWERPOINT INTEGRATION
try
{
pwptApp = (Microsoft.Office.Interop.PowerPoint.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPoint.Application");
pwptApp.ActiveWindow.Selection.TextRange.Font.Color.RGB = System.Drawing.ColorTranslator.ToOle(changeColor);
if (pwptApp.ActiveWindow.Selection.TextRange.Text.Trim() == "") pwptApp.ActiveWindow.Selection.TextRange.Text = " ";
}
catch (System.Exception excp)
{
}
//MICROSOFT OUTLOOK INTEGRATION
try
{
Microsoft.Office.Interop.Outlook.Application otlkApp = (Microsoft.Office.Interop.Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
Microsoft.Office.Interop.Outlook.Explorer otlkExp = otlkApp.ActiveExplorer();
Microsoft.Office.Interop.Outlook.Selection otlkSel = otlkExp.Selection;
Microsoft.Office.Interop.Outlook.MailItem otlkMsg = otlkApp.ActiveInspector().CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;
Microsoft.Office.Interop.Outlook.Inspector insp = otlkMsg.GetInspector;
Microsoft.Office.Interop.Word.Document otlkDoc = (Microsoft.Office.Interop.Word.Document)insp.WordEditor;
string sepSel = otlkDoc.Application.Selection.Text;
byte rColor = changeColor.R;
byte gColor = changeColor.G;
byte bColor = changeColor.B;
if (sepSel.Trim() == "\r") return;
char cReturn = (char)13;
if (sepSel == cReturn.ToString()) return;
if (sepSel != "")
{
otlkMsg.HTMLBody = otlkMsg.HTMLBody.Replace(sepSel, "<font style = 'color: rgb(" + rColor.ToString() + ", " + gColor.ToString() + ", " + bColor.ToString() + ")'>" + sepSel + " </font>");
}
else
{
return;
}
prevOutlookContents = otlkMsg.HTMLBody;
}
catch (System.Exception excp)
{
}
Related
So I'm working on an app that will be able to read the outlook calendars for a set of individuals and build an itinerary for them. I've got it pretty much working except that when I scrape a user's calendar, I'm not getting any information on the events they have marked as private.
Let me make it clear that I'm not trying to peer into a user's calendar and read their darkest secret appointment titles, but I would still like to be able to show that this person is unavailable during that time. For example in Outlook proper it just shows as "Private Appointment" - which is exactly what I want to be able to do in my app.
Here's the code I've got for scraping the user's calendar:
private Calendar CreateCalendar(String User_Name, String Initials, DateTime Week)
{
string filter = "[Start] >= '"
+ Week.ToString("g")
+ "' AND [End] <= '"
+ Week.AddDays(7).ToString("g") + "'";
Microsoft.Office.Interop.Outlook.Application App = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = App.GetNamespace("MAPI");
//Resolve the person whose calendar We're trying to read.
Outlook.Recipient rm = App.Session.CreateRecipient(User_Name);
if (rm.Resolve())
{
try
{
Outlook.Folder calFolder = App.Session.GetSharedDefaultFolder(rm, Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
Outlook.Items CalItems = calFolder.Items;
CalItems.IncludeRecurrences = true;
CalItems.Sort("[Start]", Type.Missing);
//Search for Items within the pre-defined time range.
Outlook.Items restrictItems = CalItems.Restrict(filter);
if (restrictItems.Count == 0)
{
Debug.Print("No Items Found");
return new Calendar(User_Name, Initials);
}
else
{
//Create our internal representation of their calendar, for use elsewhere.
Calendar cal = new Calendar(User_Name, Initials);
Outlook.AppointmentItem i = (Outlook.AppointmentItem)restrictItems.GetFirst();
do
{
cal.AddAppointment(i.Subject, i.Start, i.End);
i = restrictItems.GetNext();
} while (i != null);
App = null;
mapiNamespace = null;
return cal;
}
}
catch (Exception ex)
{
App = null;
mapiNamespace = null;
throw new AccessViolationException(User_Name + " was resolved but could not access their calendar. Have they set you up as a delegate?", ex);
}
}
else
throw new AccessViolationException("The name " + User_Name + " was not resolved, make sure their name in the RM List is spelled correctly. If you can enter their name as a recipient in an outlook mail message and it resolves correctly when you click 'Check Names', then it should work!");
}
I'm not sure if private events are contained in the same "Folder" in outlook's data structures, so maybe I'm just not looking in the right spot?
I've been having trouble googling this because "private" is a reserved word in C# that basically hits on every single post with code and a function declaration in it. Hopefully you guys will be more helpful.
Thanks!
I face this problem when I try the exe at the user's end. The user has MicosoftExcel 2000 and I have execel 2003. Can someone please help me.
I have created this tool in c# and have used COM
if( strDataSheetFile.Trim().EndsWith( ".xls" ) || strDataSheetFile.Trim().EndsWith( ".xlsx" ) )
{
System.IO.StreamWriter file = null;
if (IfAbFile)
{
file = new System.IO.StreamWriter(AbaqusDeckFile.ToString(), true);
}
else
{
string[] strFILEnamesSplit = strDataSheetFile.Split(new Char[] { '\\' });
string ExpFile = "";
int ilnt = 0;
foreach (string strVal in strFILEnamesSplit )
{
if (ilnt < (strFILEnamesSplit.Length - 1))
{
ExpFile += strVal;
ExpFile += "/";
}
else
ExpFile += "Deck.inp";
ilnt += 1;
}
file = new System.IO.StreamWriter(ExpFile.ToString(), true);
}
List<List<double>> List_SheetValues = new List<List<double>>();
Excel.Application objexcel;
Excel.Workbook wbexcel;
Excel.Worksheet wsheet;
objexcel = new Excel.Application();
//strDataSheetFile = #"C:\Ajoy\Demos\IsoMount\IsoMount_Springs_database_updated.xls";
if (File.Exists(strDataSheetFile))
wbexcel = objexcel.Workbooks.Open(strDataSheetFile);
else
{
MessageBox.Show(" Please state the number of springs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.UseWaitCursor = false;
return;
}
This is probably happening in you use early (compile time) binding to the Excel type library.
The user has a different version of the type library (2000 vs 2003 on your machine).
Have you tried installing Excel 2000 on your machine & compiling your app by linking to the 2000 type library.
Alternatively, if you are not using any 2003 specific features AND the the functions & objects you are using have not changed between those 2 versions, you can try late (runtime) binding.
There'll be a slight performance hit & you lose intellisense in the IDE but should make your app portable across all Excel versions that support those objects & functions
i think the problem is you are compiling your Project as 'x64' 64bit instead of that compile it as x86 32 bit Application. Follow the below steps:
->Right click on Project
->Select Properties
->Select Build tab
->Change "Platform Target" to "x86"
->now run the Project.
I found yesterday on google iTextSharp for pdf filling data.
but when i trying to read pdf ,i am not getting acrofields from pdf .
Here is code
private void ListFieldNames()
{
string pdfTemplate = #"E:\Vikas\Projects\PdfWriter\PdfWriter\nbc-app.pdf";
// create a new PDF reader based on the PDF template document
PdfReader pdfReader = new PdfReader(pdfTemplate);
AcroFields formfields = pdfReader.AcroFields;
// create and populate a string builder with each of the
// field names available in the subject PDF
foreach (KeyValuePair<string, AcroFields.Item> de in formfields.Fields)
{
sb.Append(de.Key.ToString() + Environment.NewLine);
}
// Write the string builder's content to the form's textbox
txtbx.TextMode = TextBoxMode.MultiLine;
txtbx.Width = 500;
txtbx.Rows = 40;
txtbx.Text = sb.ToString();
//txtbx.SelectionStart = 0;
}
Than i was doing debugging i saw reader.javascript throwing error (error is below )
if (typeof(this.ADBE) == "undefined")
this.ADBE = new Object();
ADBE.LANGUAGE = "ENU";
ADBE.Viewer_string_Title = "Adobe Acrobat";
ADBE.Viewer_string_Update_Desc = "Adobe Interactive Forms Update";
ADBE.Viewer_string_Update_Reader_Desc = "Adobe Reader 7.0.5";
ADBE.Reader_string_Need_New_Version_Msg = "This PDF file requires a newer version of Adobe Reader. Press OK to download the latest version or see your system administrator.";
ADBE.Viewer_Form_string_Reader_601 = "This PDF form requires a newer version of Adobe Reader. Although the form may appear to work properly, some elements may function improperly or may not appear at all. Press OK to initiate an online update or see your system administrator.";
ADBE.Viewer_Form_string_Reader_Older = "This PDF form requires a newer version of Adobe Reader. Although the form may appear to work properly, some elements may function improperly or may not appear at all. Press OK for online download information or see your system administrator.";
ADBE.Viewer_Form_string_Viewer_601 = "This PDF form requires a newer version of Adobe Acrobat. Although the form may appear to work properly, some elements may function improperly or may not appear at all. Press OK to initiate an online update or see your system administrator.";
ADBE.Viewer_Form_string_Viewer_60 = "This PDF form requires a newer version of Adobe Acrobat. Although the form may appear to work properly, some elements may function improperly or may not appear at all. For more information please copy the following URL (CTRL+C on Win, Command-C on Mac) and paste into your browser or see your system administrator.";
ADBE.Viewer_Form_string_Viewer_Older = "This PDF requires a newer version of Acrobat. Copy this URL and paste into your browser or see your sys admin.";
ADBE.Viewer_Form_string_Reader_5x = "This PDF form requires a newer version of Adobe Reader. Without a newer version, the form may be displayed, but it might not work properly. Some form elements might not be visible at all. If an internet connection is available, clicking OK will open your browser to a web page where you can obtain the latest version.";
ADBE.Viewer_Form_string_Reader_6_7x = "This PDF form requires a newer version of Adobe Reader. Without a newer version, the form may be displayed, but it might not work properly. Some form elements might not be visible at all. If an internet connection is available, clicking OK will download and install the latest version.";
ADBE.Viewer_Form_string_Viewer = "This PDF form requires a newer version of Adobe Acrobat. Without a newer version, the form may be displayed, but it might not work properly. Some form elements might not be visible at all. If an internet connection is available, clicking OK will download and install the latest version.";
if (typeof(ADBE.Reader_Value_Asked) == "undefined")
ADBE.Reader_Value_Asked = false;
if (typeof(ADBE.Viewer_Value_Asked) == "undefined")
ADBE.Viewer_Value_Asked = false;
if (typeof(ADBE.Reader_Need_Version) == "undefined" || ADBE.Reader_Need_Version < 8.1)
{
ADBE.Reader_Need_Version = 8.1;
ADBE.Reader_Value_New_Version_URL = "http://cgi.adobe.com/special/acrobat/update";
ADBE.SYSINFO = "?p=" + app.platform + "&v=" + app.viewerVersion + "&l=" + app.language + "&c=" + app.viewerType + "&r=" + ADBE.Reader_Need_Version;
}
if (typeof(ADBE.Viewer_Need_Version) == "undefined" || ADBE.Viewer_Need_Version < 8.1)
{
ADBE.Viewer_Need_Version = 8.1;
ADBE.Viewer_Value_New_Version_URL = "http://cgi.adobe.com/special/acrobat/update";
ADBE.SYSINFO = "?p=" + app.platform + "&v=" + app.viewerVersion + "&l=" + app.language + "&c=" + app.viewerType + "&r=" + ADBE.Viewer_Need_Version;
}
if (typeof(xfa_installed) == "undefined" || typeof(xfa_version) == "undefined" || xfa_version < 2.6)
{
if (app.viewerType == "Reader")
{
if (ADBE.Reader_Value_Asked != true)
{
if (app.viewerVersion < 8.0)
{
if (app.alert(ADBE.Reader_string_Need_New_Version_Msg, 1, 1) == 1)
this.getURL(ADBE.Reader_Value_New_Version_URL + ADBE.SYSINFO, false);
ADBE.Reader_Value_Asked = true;
}
else if (app.alert(ADBE.Viewer_Form_string_Viewer, 1, 1) == 1)
app.findComponent({cType:"Plugin", cName:"XFA", cVer:"2.6"});
}
}
else
{
if (ADBE.Viewer_Value_Asked != true)
{
if (app.viewerVersion < 7.0)
app.response({cQuestion: ADBE.Viewer_Form_string_Viewer_Older, cDefault: ADBE.Viewer_Value_New_Version_URL + ADBE.SYSINFO, cTitle: ADBE.Viewer_string_Title});
else if (app.viewerVersion < 8.0)
{
if (app.alert(ADBE.Viewer_Form_string_Viewer, 1, 1) == 1)
app.launchURL(ADBE.Viewer_Value_New_Version_URL + ADBE.SYSINFO, true);
}
else if (app.alert(ADBE.Viewer_Form_string_Viewer, 1, 1) == 1)
app.findComponent({cType:"Plugin", cName:"XFA", cVer:"2.6"});
ADBE.Viewer_Value_Asked = true;
}
}
}
how should i fixed this problem ?
I'm using a webbrowsercontrol to show .pdf's stored locally. At button press I want the webbrowser to show an empty page/nothing and I want to move the .pdf to a different folder. First I tried navigating to "" before moving but my .pdf was used by another process. Google told me that I probably needed to clear the browser's cache to be able to move it. I did so using the code found here: http://www.gutgames.com/post/Clearing-the-Cache-of-a-WebBrowser-Control.aspx and I even tried the alternative code line found in comment nr 2, but none of these let me move my .pdf, it's still used by another process.
What can/should I do to be able to move the file? Have I forgotten something?
At the second File.Move is where I get the error:
webBrowser1.Navigate("");
WebBrowserHelper.ClearCache();
if (calConv != "")
{
File.Move(forsDir + calConv + ".cal", forsDir + calConv.Replace("ToDo\\", "") + ".cg4");
File.Move(forsDir + calConv + ".pdf", forsDir + calConv.Replace("ToDo\\", "") + ".pdf");
}
This is how to show the PDF without using the webcontrol, using Adobe Reader instead:
Download the Acrobat SDK from http://www.adobe.com/devnet/acrobat/downloads.html
In your project add a reference to two dlls from the SDK - AxInterop.AcroPDFLib.dll and Interop.AcroPDFLib.dll
In your form's constructor add the Adobe previewer control:
// Check if the user has Adobe Reader installed, if not you could show a link to Adobe Reader installer
if (Type.GetTypeFromProgID("AcroPDF.PDF") == null)
{
pnlGetAdobe.Visible = pnlGetAdobe.Enabled = true;
}
else
{
try
{
// Initialize the Adobe control
axAcroPDF1 = new AxAcroPDF();
axAcroPDF1.Dock = DockStyle.Fill;
axAcroPDF1.Enabled = true;
axAcroPDF1.Location = new Point(0, 25);
axAcroPDF1.Name = "axAcroPDF1";
axAcroPDF1.OcxState = (AxHost.State)new ComponentResourceManager(typeof(JasperPdfReport)).GetObject("axAcroPDF1.OcxState");
axAcroPDF1.Size = new Size(634, 393);
axAcroPDF1.TabIndex = 1;
pnlCenter.Controls.Add(axAcroPDF1); // Add it to a container or instead directly to your form with this.Controls.Add(axAcroPDF1)
axAcroPDF1.BringToFront();
}
catch (COMException cex)
{
axAcroPDF1.Dispose();
axAcroPDF1 = null;
MessageBox.Show(cex.ToString());
}
catch (Exception ex)
{
axAcroPDF1.Dispose();
axAcroPDF1 = null;
MessageBox.Show(ex.ToString());
}
}
And finally load your PDF file into the control:
if (axAcroPDF1 != null && File.Exists(pdfFilename))
{
axAcroPDF1.setShowToolbar(false);
axAcroPDF1.setView("FitH");
axAcroPDF1.setLayoutMode("SinglePage");
// Load the PDF into the control
axAcroPDF1.LoadFile(pdfFilename);
axAcroPDF1.src = pdfFilename;
// Show it
axAcroPDF1.Show();
axAcroPDF1.Refresh();
}
I need to get a list of installed program on local machine with application icons. Below is the code snippet that am using to get the list of installed program and installed directory path.
/// <summary>
/// Gets a list of installed software and, if known, the software's install path.
/// </summary>
/// <returns></returns>
private string Getinstalledsoftware()
{
//Declare the string to hold the list:
string Software = null;
//The registry key:
string SoftwareKey = #"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
{
//Let's go through the registry keys and get the info we need:
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
//If the key has value, continue, if not, skip it:
if (!(sk.GetValue("DisplayName") == null))
{
//Is the install location known?
if (sk.GetValue("InstallLocation") == null)
Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
else
Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
}
}
catch (Exception ex)
{
//No, that exception is not getting away... :P
}
}
}
}
return Software;
}
Now the issue is how i can get the installed application icon ?
Thanks in advance.
To determine if its an update, there will be a key called IsMinorUpgrade. This is present and set to a 1 for updates. If it's 0 or not present, then it's not an update.
To get an icon from an executable, use this code:
VB:
Public Function IconFromFilePath(filePath As String) As Icon
Dim result As Icon = Nothing
Try
result = Icon.ExtractAssociatedIcon(filePath)
Catch ''# swallow and return nothing. You could supply a default Icon here as well
End Try
Return result
End Function
C#:
public Icon IconFromFilePath(string filePath)
{
Icon result = null;
try {
result = Icon.ExtractAssociatedIcon(filePath);
} catch { }
return result;
}
To extract icon of installed windows application first we need to figure out the location of icon for the installed windows application. This information is stored in registry at following locations -
Key name - HEKY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Value - DisplayIcon
Key name - HKEY_CLASSES_ROOT\Installer\Products{productID}
Value - ProductIcon
For more detail and code to get application icons -
http://newapputil.blogspot.in/2015/06/extract-icons-of-installed-windows_17.html