|
Hi,
I am trying to make a C# web application witch will POST an xml message to a Cisco IP phone. If I create a webpage with a text editor with the following code, it works when I open it in my browser.
<CiscoIPPhoneExecute>
<ExecuteItem Priority="0" URL="http://10.1.1.15/ciscoipservices/clock/clock.asp"/>
</ciscoipphoneexecute>
Does anyone know how I can put this into C# code and send it with a webform button? Im new to C# but im sure this could be done somehow. Thanks in advance.
|
|
|
|
|
Yikes, My XML did not show up between the text area tags!
Here is what it should be
CiscoIPPhoneExecute>
ExecuteItem Priority="0" URL="http://10.1.1.15/ciscoipservices/clock/clock.asp"/>
/CiscoIPPhoneExecute>
|
|
|
|
|
What exactly are you trying to do? If you want to use a page to post this to your phone, then you've already done it. If you just want to send that XML fragment to your phone without a web page, use the HttpWebRequest class. See the class documentation for a good example of how to POST data to the requested URL (open a request stream and write encoded data to it).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thanks for the reply. To answer your question, I am wanting to send this xml fragment to the phone without a webpage. The HttpWebRequest seems to be exactly what im looking for. Thanks! The only part I am not following from the class documentation is the Content type. Here is my code:
try
{
// Create and get a request to the phone
WebRequest req = WebRequest.Create("http://10.5.1.168/CGI/Execute");
req.GetRequestStream();
// Set the 'Method' property of the 'Webrequest' to 'POST'.
req.Method="POST";
// Data to be posted
string postData = "<CiscoIPPhoneExecute>\r\n<ExecuteItem Priority"
+"=\"0\" URL=\"http://10.1.1.15/ciscoipservices/clock/clock.asp\"/>\r\n"
+"</CiscoIPPhoneExecute>\r\n";
// Set the encoding for the data to be sent
ASCIIEncoding encoding=new ASCIIEncoding();
// Put the encoded bytes into a Byte Array
byte[] send = encoding.GetBytes(postData);
req.ContentType = "text/xml";
// Set the content length of the string being posted.
req.ContentLength=send.Length;
// Create an output stream
Stream sout = req.GetRequestStream();
// Write to the stream
sout.Write(send, 0, send.Length);
// Close the Stream object.
sout.Close();
Response.Write("It worked");
}
catch( Exception ex)
{
string except = ex.Message;
Response.Write("It failed and threw "+except);
}
When I trigger this function I get the exception: "Cannot send a content-body with this verb-type." Any ideas on what I am doing wrong? Many thanks in advance.
|
|
|
|
|
Don't make that first call to GetRequestStream if you're not going to do anything with it.
The Content-Type is the type of content in the body. Even though you're clearly using text/xml, the phone CGI may be expecting something different, like application/vnd.motorola+xml (completely made up as an example). You need to look at the SDK (if any) for your phone and determine what content-type to send using the HTTP POST method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey,
I wonder wether there is a way (using ColumnStyles, e.g.) to set the back color of the current cell in a datgrid into some value..
Thanks!
|
|
|
|
|
Yes, but you'll need to extend the DataGridColumnStyle - or the DataGridTextBoxColumn and DataGridBoolColumn to avoid implementing all their functionality - and add a BackColor (for example - could be named whatever you want) property. In the override for Edit , set the BackColor and then call base.Edit . The the overrides for Abort and Commit , reset the BackColor to the default and again call the method on the base class. In the Paint override, use the provided Graphics object to paint the background using the BackColor value on your class then call base.Paint .
See Changing the background color of cells in a DataGrid[^] for an example of conditional painting like this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have got a DataGrid (with GridTextBoxes..) and I need that whenever the user types in a certain column some value that is not correct to clear that cell..
DataGridTextBoxColumn _datagridtextBox = (DataGridTextBoxColumn) MyDataGrid.TableStyles[0].GridColumnStyles[3];
datagridtextBox.TextBox.... += new System....EventHandler(this.Execute_This);
What code Event, EventHandler and method Execute_This should write...
Thank YOUUU..
|
|
|
|
|
You don't want to use TextChanged as so many try, because that gets fired AFTER the text is committed to the TextBox and hence to the data source. Instead, handle KeyDown and if they enter an invalid value, you could event simply cancel the key event (set KeyEventArgs.Handled to true ). If not, just set TextBox.Text to an empty string or whatever else you want to do.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi.
I have a class that read a file, that's ok. How can I pass the data that I readed to the Form class?. Now I have implemented a property field in the class that holds the handle of the control and that works, but I don't want this solution and neither to pass a control reference to the class.
There's another way to fix this?.
Thank you.
Demian.
|
|
|
|
|
You can make a custom construcotr, and pass that data throuht that construcotor ...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
When you need to update references (like an instance of a Form ), you'll need a reference to that object. There's simply no other way. How you pass/access that reference is up to you. Passing a reference (not handle, which is something entirely different) to the class that reads the data in order to assign the data to that reference is one good way of doing it. Another would be to have your Form derivative use that class that reads the data and fill-in its child controls using that data, which is a more common approach.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much Heath.
Regards.
Demian.
|
|
|
|
|
Hi,
Let's have a dream. I have a class with some properties, here a sample :
public class TestClass<br />
{<br />
private int myint;<br />
private string mystring = "";<br />
<br />
public TestClass() { }<br />
<br />
[DefaultValue(100)]<br />
public int IntProp<br />
{<br />
get { return myint; }<br />
set { myint = value; }<br />
}<br />
<br />
[DefaultValue("idea")]<br />
public string StringProp<br />
{<br />
get { return mystring ; }<br />
set { mystring = value; }<br />
}<br />
}
I wonder if it is possible to set at runtime the DefaultValue for every properties. My wish is to be able to serialize theses values. So at next startup, the new defaultvalues will be used.
So what are the issues ?
- It's straightforward to enumerate the current DefaultValueAttribute of every properties.
- I think I have to use the ICustomTypeDescriptor to get a dynamic defaultValue attribute.
- I really don't know where to put the serialization and deserialization code for putting and getting back the default values. Constructor ? Desctructor ?
- Another point, by setting the DefaultValueAttribute of one propertie, will it be set for every instance of the class ?
Thanks for helping me.
---
Alexandre Jenny
|
|
|
|
|
Implement the ICustomTypeDescriptor in your class. In the implementation for GetProperties you can attach all the attributes to your <cdoe>PropertyDescriptors that you want. I use this for an object with "properties" that are allocated from a database, and I add a DefaultValueAttribute to those PropertyDescriptor s from the database as well.
If you simply want to serialize these, then you use the TypeDescriptor.GetProperties method to get the PropertyDescriptorCollection and enumerate those properties, getting the value from the DefaultValueAttribute which may be found in PropertyDescriptor.Attributes (inheritted from MemberDescriptor ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a user control that i created which contains a bunch of search varibles in the form of text boxes and drop-down lists. I include this control in the search page and a couple of others. I am trying to update the value of the textbox and drop down lists within this user control and can't. I have been able to read the values of the Controls using:
<br />
Control myKeywords = FindControl("ctl_search:tb_keywords");<br />
TextBox tb_keywords = (TextBox)myKeywords;<br />
tb_keywords.Text.ToString();<br />
But I need to update the value of those controls.
Any help you can provide would be greatly appreciated!
|
|
|
|
|
Why are you using Text.ToString ? Text already returns a string. This is a waste of CPU cycles.
If you're getting back a value (i.e., not null ) from FindControl , then just set cast to a TextBox as you're doing and set Text to some string, like tb_keywords.Text = "Some string"; .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I have to develop an Ssh client/server in c# and, enjoyed, i found that there's no c# library for .NET .
I've heard that it's possible to import classes from other language in c#, but i haven't found solution for my problem yet...
Help....
|
|
|
|
|
polkiujhy wrote:
Ssh client/server in c# and, enjoyed, i found that there's no c# library for .NET
A library to do what? The entire Secure Shell server and client? What would you be developing then?
RageInTheMachine9532
|
|
|
|
|
There's a mistake in my previous message. I wanted to say : "Ssh client/server in c# and, enjoyed, I found that there's no Ssh library for .NET"
I have to send and receive RPC messages through an ssh connection. So I have to develop first an Ssh client and server in c#, but i don't know how.
|
|
|
|
|
I haven't been able to find any classes that do Secure Shell in .NET or anything else for that matter. I have found various projects on SourceForge and other OpenSource websites. You can try this[^] Java example for code ideas.
RageInTheMachine9532
|
|
|
|
|
Why not just establish an ssh tunnel and send RPC commands to the local port, which is presumably forwarded to the remote RPC port. If the client has the ssh client install, you could simply invoke the command with the necessary parameters using the Process class.
There is one SSH client for .NET that I was able to find with a simple search on google for "SSH .NET": http://www.nsoftware.com/products/ipworksssh.aspx[^]. It's from IP*Works which, IMO, makes pretty good libraries.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am working an n-Tier application, and I have a component which is a representation of database tables (just collections of structs), I use this component as a container of data that can be sent between the tiers.
When I try to use an adding function on the server, I put the data from the client into one struct and send it as parameter to the server function but I am getting the following message
"Because of the security restrictions, the type Entities.Suppliers cannot be accessed"
as long as I try to get a list of the suppliers (returns a datatable) I have no problem.
|
|
|
|
|
Hello,
I'm fairly new to C# and I've got a syntax question. I've seen some C# syntax on the CP located above some function declorations, syntax like [sometext("more text")]. What does that mean? Where can I find documentation describing this?
An example of this syntax would be [DllImport("wininet.dll")], which I understand tells the compiler that you're importing the wininet.dll and are going to use a function in that dll.
Thanks!
|
|
|
|
|
These are called attributes. Attributes are used to further define or enhance certain metadata.
Attribute classes in .Net always end with "Attribute", although that part of the class name doesn't have to be provided when applying the attribute in code. For instance, if you wanted to look up information on DllImport in the MSDN library, you would actually look for the DllImportAttribute class.
For more information and a better starting point on attributes, try starting with this page in the MSDN library:
Introduction to Attributes[^]
Grim (aka Toby) MCDBA, MCSD, MCP+SB
|
|
|
|