|
1) Put a LinkLabel on your form.
2) Make a Click event for your LinkLabel.
3) In the LinkLabel click event, put this code:
System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"commandline");
where commandline is the commandline, which can be things like:
"C:\Program Files\Outlook Express\msimn.exe" to launch Outlook Express, or
"mailto:forum@codeproject.com" or whatever the email address is, to launch your default email program with a new email to that address.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
I wanted to build a page all in code behind so that I could learn how this is done in C#. So I tried by developing below and calling from an aspx page. It compiles fine but I just get a blank page. Does anyone have any thoughts on what is wrong?
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class myPage: Page
{
public System.Web.UI.WebControls.TextBox txtTextBox;
public System.Web.UI.WebControls.Label lblLabel;
public void CreateChildControls(HtmlTextWriter stringWriter)
{
// Use htmlWriter to write HTML.
string strOpenHTML;
strOpenHTML = "<title>My Page";
strOpenHTML += "Enter some text:";
this.Controls.Add( new LiteralControl( strOpenHTML ) );
// Add HTMLForm Tag
HtmlForm frmForm = new HtmlForm();
frmForm.ID = "myForm";
Controls.Add( frmForm );
// Add a TextBox
txtTextBox.ID = "myTextBox";
frmForm.Controls.Add( txtTextBox );
// Add a Button
Button btnButton = new Button();
btnButton.Text = "Click Here!";
//AddHandler btnButton.Click, AddressOf Button_Click;
btnButton.Click += new EventHandler(Button_Click);
frmForm.Controls.Add( btnButton );
btnButton.Text = "Click Here!";
frmForm.Controls.Add( btnButton );
// Add Page Break
frmForm.Controls.Add( new LiteralControl( "" ) );
// Add a Label
lblLabel.ID = "myLabel";
frmForm.Controls.Add( lblLabel );
// Add Closing HTML Tags
string strCloseHTML;
strCloseHTML = "";
Controls.Add( new LiteralControl( strCloseHTML ) );
}
void Button_Click( object s, EventArgs e )
{
lblLabel.Text = txtTextBox.Text;
}
}
Code to Live Live to Code
|
|
|
|
|
I have a web form that uses a WebRequest object in order to get the binary content from an .aspx
so the .aspx makes a Response.BinaryWrite and outputs a bunch of bytes
however I have the following code
WebRequest request = WebRequest.Create(serverRequest);
WebResponse response = request.GetResponse();
if (response.ContentLength > 0)
{
using (FileStream fs = new FileStream
(filePath,FileMode.Create, FileAccess.Write))
{
byte[] buffer = new byte[response.ContentLength];
response.GetResponseStream().Read(buffer, 0,
buffer.Length);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
}
when the file is saved, the size of the file is correct, however the content is not, most of the bytes dont arrive
anybody has any idea about why?
the .aspx outputs sometimes 2.5 MB, im not sure if size is causing the problem
Basically the idea of what I'm trying to do is get the binary response from an .aspx from a winform, and then save it in a file
Thanks
|
|
|
|
|
Try changing the MIME ContentType of the output stream in the aspx page.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
I have a network stream that I am reading from, and I read from it one byte at a time (i.e., as opposed to using a stream reader or requesting a whole block). I set the receive buffer size directly on the associated TcpClient to be fairly large (i.e., ReceiveBufferSize = 250k).
My question: Since I already have a buffer on the socket and I am reading one byte at a time, is there a benefit to wrapping my network stream with a buffered stream?
|
|
|
|
|
Does anyone know of an IHTMLEditHost sample for C#? The only one I can find is in C++ w/ATL. If someone can tell me where to find one in C#, it would save me alot of time.
So you know what I'm talking about, here's the C++/ATL sample[^].
TIA ,
J Dunlap
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
These interfaces are part of the Microsoft.Mshtml.dll PIA. (c:\program files\Microsoft.NET\Primary interop assemblies). And are available at run-time with IE5.5+ browsers.
You could build the type-library by recompiling the mshtml.idl file frm the Platform SDK, and then import it with tlbimp.
|
|
|
|
|
.S.Rod. wrote:
You could build the type-library by recompiling the mshtml.idl file frm the Platform SDK, and then import it with tlbimp.
I've done the former but not the latter, and I will do the latter soon. What I was looking for was basically a sample to help me along. I've read the docs and have a fairly good understanding (and it helps that I've dealt with the HTML object model on web pages), but a sample would help.
|
|
|
|
|
If i have a web server with several IPs, then how can I determine the IP number of the server in my code? Can it be determined in a C# dll, or does it have to be determined in ASP .Net and then passed down? Either way, how do I get the IP.
Thanks.
|
|
|
|
|
Request.ServerVariables("LOCAL_ADDR") have not tried but I don't see any reason why this will not work
Meg Rules
|
|
|
|
|
It gave me an IP number but not one of my machine. Got some default IP number.
|
|
|
|
|
Ok, It worked. In my IIS setup I had IP as usnassigned. Once I assign an IP the ServerVariables property works.
Thanks.
|
|
|
|
|
|
That works too. But how about this. Is there a way to get this information in a DLL, i.e., the Request object is available in ASP. Lets say the code behind calls a C# DLL to do some stuff. Is there a way to get the IP in the DLL. I dont want to pass the number around. I could save it, but what I am looking for is if there is actually an API for it.
Thanks
|
|
|
|
|
Hi Ranjan,
Not sure, but try this
If it is not a CodeBehind but a C# Component/DLL within the Web Application,
System.Net.Dns.Resolve(System.Web.HttpContext.Current.Server.MachineName)
This or a similar variant should work. What do you say?
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
I think it worked. But I have to rty it on a server with multiple IPs to be sure.
Thanks
|
|
|
|
|
Hey All,
I have an MDI parent Container, I dock a tree view control to the left of that container, and bring up various child forms on the right side of that container. Im having an issue with this, I dont want the user to beable to resize or move the child forms I bring up, I want it all done through the treeview control. When I maximize the code in the form, I set the Control Box, Minimize, and Maximize properties to false, but for some odd reason it still displays the control box and other buttons in the file menu bar of the parent container. The funny thing is, it has disabled the close and minimize buttons. Another odd point to consider is that the restore button is enabled, so if the user clicks it, my form will shrink down to its original size, but after you click the restore button and only after you click the restore button, the control box goes away. Heres the code
this.SuspendLayout();
Form cForm = new Form();
cForm.MdiParent = this;
cForm.WindowState = FormWindowState.Maximized;
cForm.FormBorderStyle = FormBorderStyle.None;
cForm.MaximizeBox = false;
cForm.MinimizeBox = false;
cForm.ControlBox = false;
cForm.Show();
this.ResumeLayout();
Any Ideas would be greatly appreciated.
Thanks,
Ryan
|
|
|
|
|
Ryan@SalamanderTechnologies wrote:
cForm.FormBorderStyle = FormBorderStyle.None;
cForm.MaximizeBox = false;
cForm.MinimizeBox = false;
cForm.ControlBox = false;
Those things work perfectly well when the child form is not maximized.
The trouble is, when a child form gets maximized, then the border used is the MDIClient's border, not the child's border. As a result, minimize/maximize/control boxes are displayed regardless of what you is set for the child form.
Since the MDIClient is a private Form member, the only way I can think of to get around this is to directly manipulate the MDIClient window style, using native code : WIN32.SetWindowLong(this.Handle, GWL_STYLE, WIN32.GetWindowLong(this.Handle, GWL_STYLE) ~ (WS_MAXIMIZEBOX|WS_MINIMIZEBOX)); // may be won't compile, but you get the idea
The MDICLient window handle can be retrieved by looking up the this.Controls collection, looking for a member of type MDIClient :
int nbControls = this.Controls.Count;
for (int i=0; i<nbControls; i++)
{
Control pCtrl = this.Controls[i];
if ( pCtrl.GetType()== typeof(System.Windows.Forms.MdiClient) )
{
...
}
}
|
|
|
|
|
Thanks for the suggestion, I thought it might have been something along those lines.
Thanks again,
Ryan
|
|
|
|
|
By the way, anyone else who runs into this problem might be helped but a little work around I've found. If you set the form to minimized initially, then call the form show method, and after that call the form maximized method, you get the desired effect. You just have to deal with the little annoying effect of the form going from minimized to maximized, which isnt really that bad.
Thanks,
Ryan
|
|
|
|
|
I have managed to sort it out. Add this following code once your child form is created (and in fact anytime a child form is created/destroyed/...) :
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern long GetWindowLong(IntPtr hWnd, int style);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SetWindowLong(IntPtr hWnd, int style, long value);
<p> </p>
const int GWL_STYLE = -16;
const long WS_MINIMIZEBOX = 0x20000;
const long WS_MAXIMIZEBOX = 0x10000;
int nbControls = this.Controls.Count;
for (int i=0; i<nbControls; i++)
{
Control pCtrl = this.Controls[i];
if ( pCtrl.GetType()== typeof(System.Windows.Forms.MdiClient) )
{
long nStyle = GetWindowLong(pCtrl.Handle, GWL_STYLE);
nStyle ^= (WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
SetWindowLong(pCtrl.Handle, GWL_STYLE, nStyle);
}
}
As I have already said, this forces the MDIClient's window style not to show either caption boxes.
|
|
|
|
|
|
1. How to check the file is good before I proceed?
ex: In C++ I check like this:
TRY { oFile = new CFile (filename, CFile::modeRead); }<br />
CATCH ( CFileException, e ) { oFile = NULL;}<br />
END_CATCH<br />
}<br />
<br />
if (oFile) <br />
{<br />
....<br />
}
How to do this in C#?
2. What's equivalent of char * in C#?
Don't and drive.
|
|
|
|
|
bool bExists = new System.IO.FileInfo(@"c:\test.txt").Exists;
long nLength = new System.IO.FileInfo(@"c:\test.txt").Length;
About char*, it's somewhat harder to answer. What's is supposed to be in managed code depends on the semantics of that char* : is it a pointer to a single char (use IntPtr, and marshal to char[] back and forth) ? is it an input string (use String in your method call) ? is it a fixed string (use StringBuilder) ? is it an output string (use ref String) ?
|
|
|
|
|
.S.Rod. wrote:
long nLength = new System.IO.FileInfo(@"c:\test.txt").Length;
This is thing works file.Length;
Is it OK?
.S.Rod. wrote:
About char*, it's somewhat harder to answer.
Wow...
In my case...Usually I do like this C++
Ex: (separator is LPCTSTR )
char* Sep = NULL;<br />
int sepLength = 0;<br />
if (sepLength = strlen (separator)) <br />
{<br />
Sep = new char [sepLength + 1];<br />
strcpy (Sep, separator);<br />
Sep[sepLength] = '\0';<br />
}
Thx Rodrigez for clarfying my newbie doubts.
Don't and drive.
|
|
|
|