New Comment on "Word_Example05"
New Comment on "Word_Example05"
New Comment on "Word_Example05"
New Post: Outlook IRibbonControl context - unable to cast to Inspector
I just started to play with NetOffice and generally it looks excellent!
However I have bumped into a problem on my first project.
I have created a ribbon button in Outlook and want to manipulate the Mailitem object when the button is pressed. The event is working well and I get the IRibbonControl object in my function.
However, I am unable to cast the control.Context property.
public void btnSaveSend_Click(NetOffice.OfficeApi.IRibbonControl control)
{
var item = control.Context as NetOffice.OutlookApi.Inspector;
var mailItem = item.CurrentItem as NetOffice.OutlookApi.MailItem;
if (mailItem != null) MessageBox.Show(mailItem.Subject);
}
The above method only returns item = null. If I try this: var item = (NetOffice.OutlookApi.Inspector)control.Context;
I get an error message: _Unable to cast COM object of type 'System._ComObject' to class type 'NetOffice.OutlookApi.Inspector'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
_
When debugging the add-in I can see that there is actually a MailItem object inside control.Context.CurrentItem, so this is all down to casting.
I have seen several code examples where this is supposed to work, but for me it doesn't.
Any help guiding me in the right direction is greatly appreciated!
Ezpl
New Post: VSTO to NetOffice
return Globals.ThisAddin;
Can you please tell me how I can get a reference to the current addin object.
PS only been using this one day and it looks like a great project, thanks.
AT
New Post: Outlook IRibbonControl context - unable to cast to Inspector
use:
Outlook.Inspector item = new Outlook.Inspector(null, control.Context);
// stuff
item.Dispose();
*Sebastian
New Post: VSTO to NetOffice
but its easy to implement i find:
// example
class MyAddin
{
MyAddn()
{
_singleton = this;
}
internal static Addin Singleton { get{ return _singleton;} }
private static Addin _singleton;
}// usage
return MyAddin.Singleton;
*Sebastian
New Post: VSTO to NetOffice
class AnotherClass()
{
public static Addin GetAddin()
{
return ????
}
}
The other class is a class I use for all my outlook projects and is a list of static helper functions, but unless they can reference the current addin they can't do much.If the functions where not static I would do below but constructor is not used with static calls.
class AnotherClass()
{
public Addin _ParentAddin;
AnotherClass(Addin FromParent)
{
_ParentAddin = FromParent;
}
public static Addin GetAddin()
{
return _ParentAddin;
}
}
Any Ideas?Thanks again for your quick response.
Andrew
New Post: VSTO to NetOffice
New Post: Erstellung Button in CommandBar nur bei Mail
Betreff: Erstellung Button in CommandBar nur bei Mail
Hallo,
ich versuche seit einiger Zeit einen Button in die Standard-CommandBars zu integrieren, aber nur, wenn ein neues Mailfenster bzw. eine vorhandene Mail geöffnet wird, also nicht beim Öffnen einer Notiz oder eines Kallendereintrages.
Hier mal mein bisheriger Stand der Dinge:
Als erstes klinke ich mich in das Event ein, wenn ein neues Fenster geöffnet wird:
void IDTExtensibility2.OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) {
_outlookApplication = new Application(null, application);
_outlookInspectors = _outlookApplication.Inspectors as Inspectors;
if (_outlookInspectors != null) {
_outlookInspectors.NewInspectorEvent += OutlookInspectorsNewInspectorEvent;
}
}
Wenn dann ein Fenster geöffnet wird, schaue ich nach, ob es ein Mailitem ist. Wenn ja, dann füge einen Button zur standardBar hinzuvoid OutlookInspectorsNewInspectorEvent(_Inspector inspector) {
try {
var citem = inspector.CurrentItem;
if (citem is MailItem) {
_standardBar = inspector.CommandBars["Standard"];
_mBttn = (CommandBarButton)_standardBar.Controls.Add(MsoControlType.msoControlButton, 1, null, 3, true);
_mBttn.Style = MsoButtonStyle.msoButtonIconAndCaption;
_mBttn.FaceId = 225; // Schloss (Icon)
_mBttn.Caption = "Test";
_mBttn.Tag = "MBUTTON";
_mBttn.ClickEvent += MCmdBarBttnClickEvent;
}
}
}
Und zum Schluß noch der Button Event:void MCmdBarBttnClickEvent(CommandBarButton ctrl, ref bool cancelDefault) {
...
ctrl.Dispose();
}
Allerdings habe ich hier das Problem, dass sich mein ProxyCount immer weiter erhöht und ich nicht weiss,
ob bei einem Count von mehreren Hundert bis Tausend nach einem Arbeitstag, dies negative Auswirkungen auf die Performance haben könnte.
Wie sieht hier ein sauberes Vorgehen aus, um die Proxys so gering wie möglich zu halten ohne z.B. das Event für den dynamisch erstellten Button
in der Standardbar zu verlieren? Was ja z.B passieren würde, wenn ich am Ende von OutlookInspectorsNewInspectorEvent ein _standardBar.Dispose(); ausführen würde.
Oder gibt es eine ganz andere Vorgehensweise, wie ich einen Button in die StandardBar bekomme, eventuell mit "ein- und ausblenden"?
Danke und viele Grüße, Daniel
New Post: Erstellung Button in CommandBar nur bei Mail
Zu deiner Frage:
NetOffice bietet für solche Fälle eine Überladung der Dispose und DisposeChildInstance Methoden an:
void Dispose(bool disposeEventLListener);
Du kannst also am Ende des Inspector Events inspector.Dispose(false); aufrufen um möglichst effizizient vorzugehen.
*Sebastian
New Post: Can't delete file after renaming due to Word file handle still present
Any updates about this issue?
Best regards
Created Unassigned: Compile error in Tutorial 10 of v1.6 [20151]
The same compilation error occurs in the .NET4.0 version of the tutorials.
New Post: COM Add-In "Not Loaded. Runtime error..."
I want to test my office add-in on my test machine. I registered it with regasm.exe name.dll /codebase
The plug-in is available in office, but I can't activate it. It tells: "Not loaded. A runtime error occurred during the loading of the COM Add-In"
I checked following:
- LoadBehavior = 3
- .Net 4 Client Profil and .Net 4.5 is installed
-
after "OnConnection" in my add-in I added an MessageBox but this do not appear. So plugin do not throw an exception.
New Post: COM Add-In "Not Loaded. Runtime error..."
New Post: Problem get outlook instance from ROT
New Post: PowerPoint hide window
I want to modify an PowerPoint file in background.
PowerPoint.Application powerPointApplication = new PowerPoint.Application();
powerPointApplication.DisplayAlerts = PpAlertLevel.ppAlertsNone;
if (Utils.IsFileLocked(filePath)) {
Utils.MessageBoxError("File (" + filePath + ") is open by a other process or can't write on it.", "POWERPOINT");
return;
}
PowerPoint.Presentation presentation = powerPointApplication.Presentations.Open(filePath);
But the PowerPoint application open, shows the presentation and close automatically.If I activate
powerPointApplication.Visible = MsoTriState.msoFalse;
I get follwoing error "Application.Visible : Invalid request. Hiding the application window is not allowed". How is it possible to hide the window or don't popup the window!?
Reviewed: NetOffice 1.6.0 (Sep 11, 2013)
Commented Issue: Cannot call VBA methods with parameters [18896]
http://netoffice.codeplex.com/discussions/402559
Comments: ** Comment from web user: buehlert **
Hi Sebastian
Thanks a lot for a fantastic release 1.6.0!
Unfortunately the macro related issue I recognized has not been fixed yet.
Is there any chance of a working update?
Thanks and best regards,
Thomas
Commented Issue: Cannot call VBA methods with parameters [18896]
http://netoffice.codeplex.com/discussions/402559
Comments: ** Comment from web user: buehlert **
Here is some code to test this easily:
Create test.ppam with following subs/functions:
```
Public Sub TestAddin()
MsgBox ("Hello")
End Sub
Public Function TestAddin2() As String
TestAddin2 = "Hello "
End Function
Public Function TestAddin3(name As String) As String
TestAddin3 = "Hello " & name
End Function
```
Now, create a C# Test method like:
```
var powerApplication = new Application();
powerApplication.Visible = MsoTriState.msoTrue;
var addin = powerApplication.AddIns.Add("D:\test\test.ppam");
addin.Loaded = MsoTriState.msoTrue;
//1. Macro, no parameters, no return value
powerApplication.Run(addin.Name + "!TestAddin");
//2. Macro, no parameters, with return value
var res = powerApplication.Run(addin.Name + "!TestAddin2");
Debug.WriteLine(res.ToString());
//2. Macro, with parameters, with return value
var res2 = powerApplication.Run(addin.Name + "!TestAddin3", new Object[] { "test" });
Debug.WriteLine(res2.ToString());
powerApplication.Quit();
powerApplication.Dispose();
```
TestAddin -> works, message box will be displayed
TestAddin2 -> works, "Hello" is returned
TestAddin3 -> crashes -> it says "Application.Run : Invalid request. Sub or function not defined"