|
I want to capture all the Internet Explorer instances on a PC and
then read source code of a web page if it was opened by any instance.
it seems that "Document.ActiveElement.InnerText;" is the key but i always receive this error before debugging the code :
object' does not contain a definition for 'ActiveElement' and no extension method 'ActiveElement' accepting a first argument of type 'object' could be found
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
string filename;
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
if (Condition)
{
textBox1.Text = ie.Document.ActiveElement.InnerText;
}
}
can any one help me if what do ?
thanks
|
|
|
|
|
I've never worked with that SHDocVw library . From the error message, I can see that the Document property of SHDocVw.InternetExplorer is an object only. Before you can navigate further to its ActiveElement property, you have to cast it to an appropriate type (and likely again for ActiveElement ). For that purpose, you have to read the documentation for that library - I do not know it!
Your code should then be something like (replace the dummy types I used!):
DocumentType document = ie.Document as DocumentType;
ActiveElementType activeElement = document.ActiveElement as ActiveElementType;
textBox1.Text = activeElement.InnerText;
|
|
|
|
|
well aside all the possible ways , there was an easy way
that i'm going to mention here .
dynamic d = ie;
object v = d.Document.ActiveElement.InnerHTML;
|
|
|
|
|
Microsoft's Remote Connectivity Analyzer tool (https://testconnectivity.microsoft.com/) is great to troubleshoot Exchange. Does any body know if there's a way to get save the analysis results automatically?
Do they have any API? Web Services? What would be a way to collect that data using an .NET application?
Any feedback, blog, or documentation is greatly appreciated.
Thank you.
|
|
|
|
|
lesponce wrote: Does any body know if there's a way to get save the analysis results automatically? You can't.
lesponce wrote: Any feedback, blog, or documentation is greatly appreciated. Terms of use are at the bottom of the page; see section 6, "use restrictions".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I need to write an Outlook 2003-2010 plugin using C# that adds two buttons to the Message Ribbon Bar (#1 on the picture) and a several buttons toolbar or a Form Region under the "Subject" line (#2 on the picture).
See image here: http://i.piccy.info/i9/8ccdf69246fbcd9171d488747c6ea189/1398291704/206810/736482/editmessage.png[^]
Currently I managed to add a button to the Ribbon toolbar, but it appears in the "Add-ins" Ribbon Bar. How do I add buttons to the "Message" Ribbon Bar?
And how do I add the Toolbar #2 ? I currently have no clue about how to add it.
Please help me!
I now have the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
namespace SendLaterToolbar
{
public partial class ThisAddIn
{
Office.CommandBar newToolBar;
Office.CommandBarButton firstButton;
Office.CommandBarButton secondButton;
Outlook.Explorers selectExplorers;
Outlook.Inspectors inspectors;
Office.CommandBarButton _objEmailToolBarButton;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
selectExplorers = this.Application.Explorers;
inspectors = this.Application.Inspectors;
selectExplorers.NewExplorer += new Outlook.ExplorersEvents_NewExplorerEventHandler(newExplorer_Event);
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(AddToEmail);
AddToolbar();
}
private void newExplorer_Event(Outlook.Explorer new_Explorer)
{
((Outlook._Explorer)new_Explorer).Activate();
newToolBar = null;
AddToolbar();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void AddToolbar()
{
if (newToolBar == null)
{
Office.CommandBars cmdBars =
this.Application.ActiveExplorer().CommandBars;
newToolBar = cmdBars.Add("NewToolBar",
Office.MsoBarPosition.msoBarTop, false, true);
}
try
{
Office.CommandBarButton button_1 =
(Office.CommandBarButton)newToolBar.Controls
.Add(1, missing, missing, missing, missing);
button_1.Style = Office
.MsoButtonStyle.msoButtonCaption;
button_1.Caption = "Button 1";
button_1.Tag = "Button1";
if (this.firstButton == null)
{
this.firstButton = button_1;
firstButton.Click += new Office.
_CommandBarButtonEvents_ClickEventHandler
(ButtonClick);
}
Office.CommandBarButton button_2 = (Office
.CommandBarButton)newToolBar.Controls.Add
(1, missing, missing, missing, missing);
button_2.Style = Office
.MsoButtonStyle.msoButtonCaption;
button_2.Caption = "Button 2";
button_2.Tag = "Button2";
newToolBar.Visible = true;
if (this.secondButton == null)
{
this.secondButton = button_2;
secondButton.Click += new Office.
_CommandBarButtonEvents_ClickEventHandler
(ButtonClick);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void AddToEmail(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem _ObjMailItem = (Outlook.MailItem)Inspector.CurrentItem;
if (Inspector.CurrentItem is Outlook.MailItem)
{
_ObjMailItem = (Outlook.MailItem)Inspector.CurrentItem;
bool IsExists = false;
foreach (Office.CommandBar _ObjCmd in Inspector.CommandBars)
{
if (_ObjCmd.Name == "MyEmailToolBar")
{
IsExists = true;
_ObjCmd.Delete();
}
}
Office.CommandBar _ObjCommandBar = Inspector.CommandBars.Add("MyEmailToolBar", Office.MsoBarPosition.msoBarBottom, false, true);
_objEmailToolBarButton = (Office.CommandBarButton)_ObjCommandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true);
if (!IsExists)
{
_objEmailToolBarButton.Caption = "My Email ToolBar Button";
_objEmailToolBarButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow;
_objEmailToolBarButton.FaceId = 500;
_objEmailToolBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(_objEmailToolBarButton_Click);
_ObjCommandBar.Visible = true;
}
}
}
private void ButtonClick(Office.CommandBarButton ctrl, ref bool cancel)
{
MessageBox.Show("You clicked: " + ctrl.Caption);
}
private void _objEmailToolBarButton_Click(Office.CommandBarButton ctrl, ref bool cancel)
{
MessageBox.Show("My Email ToolBar ...");
}
#region VSTO generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
|
|
|
|
|
M A V wrote: Currently I managed to add a button to the Ribbon toolbar, but it appears in the
"Add-ins" Ribbon Bar. How do I add buttons to the "Message" Ribbon Bar?
First check here[^] whether that's a supported scenario.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I belive yes because I saw other plugins doing such integration.
|
|
|
|
|
Dear Experts,
I have a tree is filled dynamically, and I have a list of Forms, so I need when I click on Tree Node that assigned to specific form to open the Form.
I hope To find a solution for this,
Ahmad
|
|
|
|
|
Have some Google Foo[^]. From the treeview I presume you get the form name as a string, then use that to open a form.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you,
I have found the following Code, it is working properly:
private void button1_Click(object sender, EventArgs e)
{
Form Frm = GetFormByName(textBox1.Text );
Frm.Refresh();
Frm.Text = "Test";
Frm.StartPosition = FormStartPosition.CenterScreen;
Frm.MaximizeBox = false;
Frm.Show();
}
public Form GetFormByName(string FormName)
{
Type T = Type.GetType(FormName, false);
if (T == null)
{
string Fullname = Application.ProductName + "." + FormName;
T = Type.GetType(Fullname, true, true);
}
return (Form)Activator.CreateInstance(T);
}
|
|
|
|
|
Hi, please try
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
Form1 form=new Form1();
form.Show();
}
|
|
|
|
|
Consider using a Dictionary<string, Form> to 'Show existing instances of Forms; or, consider using a Dictionary<string,Type> to create and 'Show new instances based on Type:
private Dictionary<string, Form> dctStrForm;
private Dictionary<string, Type> dctStrType;
private void Form1_Load(object sender, System.EventArgs e)
{
dctStrForm = new Dictionary<string, Form>
{
{"Form2", new Form2()},
{"Form3", new Form3()},
{"Form4", new Form4()},
{"Form5", new Form5()}
};
dctStrType = new Dictionary<string, Type>
{
{"Form2", typeof(Form2)},
{"Form3", typeof(Form3)},
{"Form4", typeof(Form4)},
{"Form5", typeof(Form5)}
};
}
private void btnShowFormFromString_Click(object sender, System.EventArgs e)
{
string frmCandidate = textBox1.Text;
if (dctStrForm.ContainsKey(frmCandidate))
{
dctStrForm[frmCandidate].Show();
}
else
{
MessageBox.Show("I don't have a Form named: " + frmCandidate);
}
}
private void btnCreateAndShowFormFromString_Click(object sender, System.EventArgs e)
{
string frmCandidate = textBox1.Text;
if (dctStrType.ContainsKey(frmCandidate))
{
Type newFormType = dctStrType[frmCandidate];
Form newForm = Activator.CreateInstance(newFormType) as Form;
newForm.Show();
}
else
{
MessageBox.Show("I don't have a Form of Type: " + frmCandidate);
}
} Note that in the second example we are ignoring the probably obvious need anyone would have to keep track of new Form instances created, install EventHandlers for Events raised by the new Forms, etc.
If you have assigned the 'Text or 'Type of your different Forms to the 'Tag Property of TreeNodes in your TreeView, then you can easily use the same techniques shown here:
0. in the After_Select EventHandler
1. check if the selected Node Tag is non-null: skip if null
2. if necessary cast the Tag to a Type
3. use the code shown above with either string or Type as needed.
“I speak in a poem of the ancient food of heroes: humiliation, unhappiness, discord. Those things are given to us to transform, so that we may make from the miserable circumstances of our lives things that are eternal, or aspire to be so.” Jorge Luis Borges
modified 26-Apr-14 7:50am.
|
|
|
|
|
I have a web api application that has an ImageController. This controller works perfectly on my development environment (localhost) and i use Fiddler to test and see results. I purchased a hosting plan on GoDaddy and deployed my project. When using a Post method to some action, the data received in my JObject is null(locally data is received correctly as a json string)
this is my action signature:
public void Post([FromBody]JObject jsonData)
Request Headers:
User-Agent: Fiddler
Host: X.com
Content-Length: 6424
Content-Type: application/json; charset=utf-8
Request Body is a json string that is validated and looks good.
Any help is appreciated.
|
|
|
|
|
I feel like having lost my OO knowledge. Actually, the problem looks simple: I want to create a class which operates on an object which
- inherits from System.Windows.Forms.Form
- implements the interface IDescribedActionsProvider
at the same time.
I could create a new Form type
public abstract class SpecialForm : Form, IDescribedActionsProvider
and require a parameter of that SpecialForm type.
But it does not work here: most of our Forms inherit from OurCompanyForm which need not implement IDescribedActionsProvider , and some of our forms do not inherit therefrom, but when they implement the interface, they should be an acceptable parameter.
It is composition what is required here, not inheritance.
Then I thought of Generics. I could define my class like
public class FormController<T> : IDisposable where T : Form, IDescribedActionsProvider
{
T _ControlledForm;
OtherType _OtherObject;
internal FormController(OtherType otherObject, T controlledForm)
{
_OtherObject = otherObject;
_ControlledForm = controlledForm;
....
}
It would work the way I intended, but it feels totally wrong:
That's not what Generics (see MSDN[^]) were meant for.
And I get problems when I want to create that FormController object in a Factory (because of the OtherType which is created there) which is not generic, i.e. a function like
public FormController<T> CreateFormcontroller(T controlledForm)
is not possible because T not defined here... And using "SpecialForm" instead of T does not work because of composition vs. inheritance.
What do you suggest? "Duck Typing" - but that's not a good OO practise either?
|
|
|
|
|
Bernhard Hiller wrote: What do you suggest?
Bernhard Hiller wrote: I want to create a class which operates on an object which implements ..OurCompanyForm; wouldn't that be easier?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
No, it does not work: there are other Forms implementing the interface, but not inheriting from OurCompanyForm.
|
|
|
|
|
Bernhard Hiller wrote: That's not what Generics (see MSDN[^]) were meant for.
Although MSDN keeps referring to collections, that's not the only use for generics. The problem you've described is a perfect candidate for generics.
Bernhard Hiller wrote: public FormController<T> CreateFormcontroller(T controlledForm)
is not possible because T not defined here...
That's easy to fix:
public FormController<T> CreateFormcontroller<T>(T controlledForm) where T : Form, IDescribedActionsProvider
{
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, that works. My +5. When I tried to write it like that, I got one or more of those many <T>s wrong.
But it still feels a little "ugly"...
|
|
|
|
|
Hi,
I have created a Windows Service and i am calling a web service method from my windows service.
When i run my windows service, i am getting the below error
"Configuration system failed to initialize"
Note: The services are installed and my web service is running from Visual Studio (ASP.NET development server)
Please help to fix this error.
|
|
|
|
|
That's typically caused by a small typo in the configuration file, e.g. a space between a < and the following keyword...
|
|
|
|
|
Thank you. I think that was the problem (typo in config or any changes). I recreated my project and it worked well for me.
Thank you again.
|
|
|
|
|
I created one FormBase class in my Class file as following :
public partial class FormBase : Form
{
public FormBase()
{
this.Load += new System.EventHandler(this.FormLoad);
}
public void PanelUtil(Panel p1, Form f1)
{
p1.Left = (f1.ClientSize.Width - p1.Width) / 2;
p1.Top = (f1.ClientSize.Height - p1.Height) / 2;
}
protected virtual void FormLoad(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
}
and my all form contains the following code:
public partial class Form1 : FormBase
{
public Form1()
{
InitializeComponent();
}
private void Form1_Resize(object sender, EventArgs e)
{
PanelUtil(panel1, this);
}
}
But i don 't want to write Resize method and call
private void Form1_Resize(object sender, EventArgs e)
{ PanelUtil(panel1, this); } in all my windows forms.
I want to that when i inherit FormBase class then it automatically gives me output as my panel is center.
|
|
|
|
|
Member 10347092 wrote: I want to that when i inherit FormBase class then it automatically gives me output as my panel is center. Add the panel to the mainform; or loop all the controls on the form and look for the panel that needs to be resized.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
..what's not good about the answer?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|