|
So you want to read data from SQL Server?
You'll need to create a SqlConnection[^] to connect to your database.
You'll need a SqlCommand[^] to issue the select command to the database.
Beyond that, you'll need to store the data in something. You can use a custom class, or a DataSet /DataTable .
Finally, you'll need to bind the data to the tree. How you do that depends on what technology stack you are using.
|
|
|
|
|
I am trying to develop a VSTO 2010 Word Addin. It has a custom task pane with a countdown timer (user control) in it. Idea is that when a word document is opened total time (in hours and minutes) is passed to the Addin which in turn passes it to the countdown timer control. When i run the addin in VS2010 and pass the user control two integers values i.e. hours and minutes in the Addin_Startup it works fine.
Now i am trying to open a word document on button click from an asp.net page. When i click the button a word document should open and time in hours and minutes should be passed to the addin which will then give it to the user control and the timer should run for the given time.
Problem is i cant figure out how to pass two integers to the addin and where to pass them. Following is my code which sometimes give "Catastrophic failure error" and other times it gives me "Unable to cast COM object of type 'System.__ComObject' to interface type 'MyWordAddin.IAddInUtilities'"
ThisAddin Class
namespace MyWordAddin
{
public partial class ThisAddIn
{
private ctlClock myUserControl;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
private int hour, min;
private AddInUtilities utilities;
protected override object RequestComAddInAutomationService()
{
if (utilities == null)
{
utilities = new AddInUtilities();
}
return utilities;
}
public int Min
{
get { return min; }
set { min = value; }
}
public int Hour
{
get { return hour; }
set { hour = value; }
}
public Microsoft.Office.Tools.CustomTaskPane MyCustomTaskPane
{
get { return myCustomTaskPane; }
set { myCustomTaskPane = value; }
}
public void ThisAddIn_Startup(object sender, System.EventArgs e)
{
myCustomTaskPane.VisibleChanged += new EventHandler(myCustomTaskPane_VisibleChanged);
}
public void setTime(int h, int m)
{
Hour = h;
Min = m;
myUserControl = new ctlClock(Hour, Min);
myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl, "Remaining Time");
myCustomTaskPane.Visible = true;
}
private void yCustomTaskPane_VisibleChanged(object sender, System.EventArgs e)
{
Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked = myCustomTaskPane.Visible;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
AddinUtilities class
namespace MyWordAddin
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IAddInUtilities
{
void setAddinTime(int h, int min);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddInUtilities : StandardOleMarshalObject,IAddInUtilities
{
public void setAddinTime(int hour, int min)
{
Globals.ThisAddIn.setTime(hour, min);
}
}
}
Controller Application which tries to open word document and send two integers to the addin
namespace ControllerApplication
{
public class CCWordApp
{
private Word._Application oWordApp;
public Word._Application OWordApp
{
get { return oWordApp; }
set { oWordApp = value; }
}
private Word.Document oWordDoc;
public Word.Document OWordDoc
{
get { return oWordDoc; }
set { oWordDoc = value; }
}
public CCWordApp()
{
oWordApp = new Word.Application();
oWordDoc = new Word.Document();
}
public void Open()
{
object addinName = "MyWordAddIn";
Microsoft.Office.Core.COMAddIn addin = oWordApp.COMAddIns.Item(addinName);
IAddInUtilities utils = null;
utils = (IAddInUtilities)addin.Object;
utils.setAddinTime(0, 8);
Object oMissing = System.Reflection.Missing.Value;
oWordApp.Visible = true;
oWordDoc = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oWordDoc.Activate();
}
When i run the controller application, upon click event of start button it some times give me "Catastrophic failure" other times it gives me "Unable to cast COM object of type 'System.__ComObject' to interface type 'MyWordAddin.IAddInUtilities'" and sometimes it stucks on the last line of code saying "An object instance not passed to and object". I have bold selected the code where error arises. I cant figure out what really is the problem here and why i cant pass two simple integers to my addin. There sure be something i am doing in a very wrong manner. Please guide me.
|
|
|
|
|
Shah Ali Haider wrote: Now i am trying to open a word document on button click from an asp.net page.
I think that's the problem - Office automation is not supported on the server:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Shah - I'm sorry that I can't offer a constructive solution other than to agree that the issue sounds likely because you are trying to run it on an ASP.NET server. Try running the add-in on a stand alone box and see what the behaviour is there.
On a side not, let me congratulate you on asking your question in the way you have. You outlined what the problem was, gave us just enough code to provide context, highlighted where the problem was, and generally crafted the question in such a way that it pains me not to give you a definitive answer - I would love to say, "oh you need to initialise X to get this to work". Congratulations on such an excellent question - if there were more like yours, people would be falling over themselves to answer questions here.
|
|
|
|
|
WebRequest and WebResponse has issues
I wrote a C# program that uses WebRequest and WebResponse to perform a simple web crawler. I discovered something about web sites. Web browsers such as IE and FireFox offer the capacity to view the HTML source code. But it seems that html code that is sent to the browser is one thing and what the browser interprets and displays is something else. For example, if you run a google search in IE and run the same google search in FireFox, the content that you can see when you view the source in IE will NOT have the hyperlinks and content from the search results, but you can see the html hyperlinks and content from the search results when you view the source in FireFox. So my question is this. How do you specialise the WebRequest and WebResponse to show the content after it is processed by the browser instead of before?
|
|
|
|
|
Xarzu wrote: WebRequest and WebResponse has issues
No, really they dont. What you go on to describe has nothing to do with the way you make an http, ftp or any other sort of request/response using WebRequest and WebResponse.
Makers of browsers are free to parse and change the raw content they get from a web server in any way they see fit, what you are doing is making the raw request and getting back the raw response. Using the classes you mention, you will have no way of showing the "content after it is processed by the browser". The only way to do that is get the browser (or an embedded web browser control) to make the request for you.
I suspect the real problem you're facing is badly formatted, or even invalid HTML. In which case this is a known problem with many solutions - the most common of which is probably the HTML Agility pack[^]
|
|
|
|
|
Just to be clear, my goal is to programatically get search results from a google search.
After looking closely at the different html source from IE and firefox and seeing the point at which they start to differ, I can safely conclude that what is happening is that firefox is showing the html prior to the browser running the javascript and IE is showing the html that results after javascript has been processed by the browser.
I think maybe I need to format what I sent to the WebRequest.Create method, but the question I know have is this. How do I send to this method the desire that I want to create the WebRequest such that I set the visibility to hidden. I believe that therein might lie the key to getting this done. It seems that the javascript processes the html in IE because the visibility is not hidden.
|
|
|
|
|
Quote: after it is processed by the browser instead of before? And what do you mean by that? It is not hard really to differentiate html across browsers. Google is known from that. To get html for FireFox, IE, Android etc. just change UserAgent HTTP header:
http://tools.ietf.org/html/rfc2616#section-14.43[^]
No more Mister Nice Guy... >: |
|
|
|
|
|
Agree 100%.
This can be accomplished by checking the Request.UserAgent in ASP.NET and the sending different output. Easy way to optimise your code for each browser and not to have to send everything down the wire.
|
|
|
|
|
my goal is to programatically get search results from a google search.
Using WebRequest and WebResponse yelds results like I see in IE where the (if I look at the processed HTML source) javascript manages to hide the search engine results from google after the browser processes the javascript.
The source code from Firefox is before html is processed by the browser and the javascript manages to hide the content.
How do I programatically make web requests to be like it is in Firefox?
|
|
|
|
|
I don't get it. If you wan't to get html for FF just use FF User-Agent.
If you want to have HTML after it is swallowed by JS then I have 2 questions: why you need this anyway? why do you think it is even doable in C#, it's JS code how are you imagine to execute JS code by c# program?
No more Mister Nice Guy... >: |
|
|
|
|
|
the source display in IE differs from FireFox on the exact same page.
If you use google in these two browsers, IE manages to have the resulting content -- the search result -- hidden in the html source.
|
|
|
|
|
As I wrote before Google feeds different browsers with different html.
Just choose one that suits you best.
No more Mister Nice Guy... >: |
|
|
|
|
|
Hi
I found here in an article, a ready function which returns the square root of biginteger, but I can't understand how it works. Can someone please explain me the algorithm and why it works:
public static BigInteger IntegerSqrt(BigInteger n)
{
BigInteger oldValue = new BigInteger(0);
BigInteger newValue;
newValue=n;
while (BigInteger.Abs(newValue - oldValue) >=1)
{
oldValue = newValue;
newValue = (oldValue + (n / oldValue)) /2;
}
return newValue;
}
thanks
|
|
|
|
|
|
In fact, this implementation doesn't always work!
try IntegerSqrt(3)
oldValue and newValue will alternate between 1 and 2
Changing the while condition from >= to > will enable the loop to terminate.
|
|
|
|
|
Maybe its mistake declaring root of number as int since roots are usually fractional numbers.
No more Mister Nice Guy... >: |
|
|
|
|
|
No, they're never fractional numbers (unless you'd count n/1 ). A square root is either an integer or an irrational number.
|
|
|
|
|
True, but I think he meant that they are usually non-integers.
|
|
|
|
|
Perhaps. I didn't vote him down, by the way.
|
|
|
|
|
|
Um... Maybe I am missing something (English is not my native language but if I am understand correctly square root is this http://en.wikipedia.org/wiki/Square_root#As_decimal_expansions[^]) How is this a usually integer? Irrational number you get only if you take sqrt of negative number. You can get sqrt of fractional to. And how is this an int?
People which voted me down before plaese forgive me if I get something wrong cause english related to math is not my strong point.
No more Mister Nice Guy... >: |
|
|
|
|
|
The square root of a perfect square is an integer.
The square root of anything else is an irrational number[^].
n.podbielski wrote: Irrational number you get only if you take sqrt of negative number. That's imaginary. Also irrational, usually.
|
|
|
|
|
Thats what I meant. Thanks for clarifying this to me
No more Mister Nice Guy... >: |
|
|
|
|
|
Hi,
how set request value for WSDL choice element - see example:
ws_test.AType my_ws = new AType();
my_ws.AData = new ADataType();
my_ws.AData.Item ??
namespace ws_test
{
[Serializable]
[DebuggerStepThrough]
[XmlType(AnonymousType = true, Namespace = "urn:cz:aaa:bbb:schemas v1")]
[GeneratedCode("System.Xml", "4.0.30319.1")]
[DesignerCategory("code")]
public class ATypeReq
{
public ATypeReq();
public ADataType AData { get; set; }
}
[Serializable]
[DesignerCategory("code")]
[GeneratedCode("System.Xml", "4.0.30319.1")]
[DebuggerStepThrough]
[XmlType(Namespace = "urn:cz:aaa:bbb:schemas:xxx:v2")]
public class ADataType
{
public ADataType();
[XmlElement("AElement", typeof(ADataTypeAA))]
[XmlElement("BElement", typeof(ADataTypeBB))]
public AStavAbstractType Item { get; set; }
}
}
<xs:complextype name="ADataType">
<xs:annotation>
<xs:documentation xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:lang="cs">
<xs:choice>
<xs:element name="AElement">
<xs:complextype>
<xs:complexcontent mixed="false">
<xs:extension base="edi:AStavAbstractType">
<xs:sequence>
<xs:element minoccurs="0" name="AA" type="edi:AAStavType">
<xs:element name="BElement">
<xs:complextype>
<xs:complexcontent mixed="false">
<xs:extension base="edi:AStavAbstractType">
<xs:sequence>
<xs:element name="BB" type="edi:BBStavType">
Thanks,
Marián
|
|
|
|