|
Hi all:
I'm a total newbie to C#, but would like to know if there is a freeware implementation of the zip component for data compression.
I have used a similar component in C++ for years but have not seen a similar implementation for C#.
TIA,
Martin.
---
Regards,
Martin.
|
|
|
|
|
|
Thanks James, just what the doctor ordered )
---
Regards,
Martin.
|
|
|
|
|
hello,
i want to know what is
c# equivalent of delay() in c/c++
LOOKING FOR HELP
ASIM
Asim
|
|
|
|
|
|
C# Code:
<font color="blue">private</font> <font color="blue">void</font> button2_Click(<font color="blue">object</font> sender, System.EventArgs e) <br> { <br> MessageBox.Show("Do some stuff!"); <br> <br> System.Threading.Thread.Sleep(5000); <font color="DarkGreen">
hope that helps.
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
i don't think there is any sleep() method in c#
?
ASIM
Asim
|
|
|
|
|
yes it's System.Threading.Thread.Sleep , like posted above.
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
after i developed my application with C# i find a problem to distribute it, as i have to ask my clients to install the .net frame work
what i want is a tool or a way to make install wizard that install the .net frame work beside the required dll
can anyone help in that?
something like the package and deployment in VB or install shiled
eng.hany
|
|
|
|
|
VS.NET comes with a handy install creation wizard, you can create setup and deployment package using that. It has options to pull in the runtime on demand,it can also take output from other projects on the solution.
- Kannan
|
|
|
|
|
No it doesn't. The CLR merge module it has is only to satisfy dependencies with .NET Framework assemblies. This is clearly outlined in the .NET Framework SDK docs / MSDN. To do this, you need to write a bootstrapper (executable) that checks the necessary registry key and installs the framework before continuing the Windows Installer portion of your application (something I happen to know a lot about and follow closely).
Wise for Windows Installer (www.wisesolutions.com) did it right: the bootstrapper should also see if Windows Installer 2.0 is installed (the MSI runtime). Since it is required for .NET and the .NET installation requires Windows Installer 2.0 (makes sense, right?), your bootstrapper can merely check to see if .NET is installed. If it isn't, you need to install it anyway, which includes the Windows Installer 2.0. If MSI 2.0 is installed but not .NET, no harm done.
If you look in the framework SDK docs (in the TOC), there is a lengthy topic on deploying .NET with your application. The MSM that is meant only to satisfy dependencies (which is why it is marked as Ignore by default) and only includes assemblies - it does not include the CLR, Fusion, or anything else required for .NET to actually run!
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
Thanks for the clarification, I had thought the installer would take care of installing the runtime along with the application. I guess .Net or not installation is always going to be a pain. I will go through the docs. thanks again.
Cheers,
Kannan
|
|
|
|
|
|
I would like to know, if it is possible,or should I say feasible to have remoted window form..in the event I am being ambiguous I will explain..
Can I remote a Window form class so that a client can just connect to the remoted object and activate it, and run it on client side..so that virtually no code for that form is available on client side..other than perhaps an class interface for the remoted forms..I am sure with enough MarshalByRef or Serialization attributes, it is possible, but was not sure if it was possible?
Thanks for your time guys/gals
-Lucas
|
|
|
|
|
How do I make the form show spaces for a string that has spaces following the last character? For example: "ABCDE ". The label never shows the spaces after it. Thanks.
Ripsi
|
|
|
|
|
you wont see the space, because it's just a space , but you can check if there's a space at the end of the label very easily , eg:
VbCode:
<font color="blue">private</font> <font color="blue">void</font> button2_Click(<font color="blue">object</font> sender, System.EventArgs e) <br> { <br> label1.Text="sometext "; <br> } <br> <br> <font color="blue">private</font> <font color="blue">void</font> label1_Click(<font color="blue">object</font> sender, System.EventArgs e) <br> { <br> <font color="#0000FF">if</font>(label1.Text.EndsWith(" ")) <br> { <br> MessageBox.Show("found a space!"); <br> } <br> } <br>
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
I am trying to send a document (text/plain) to a server (.aspx page). I am always having a time-out (if I specify GET, I get a 404, as I expected).
When I look in the IIS log, I see the following:
2003-07-02 20:17:03 127.0.0.1 - 127.0.0.1 80 POST /Test/WebForm1.aspx - 500 87 -
This appears in the log whether or not the page exists on the server.
The 87 error means "The parameter is incorrect". I suspect that it has something to do with the Content-Length. Here is a code snippet I use to fill the HTTP stream with the document:
protected virtual void FillHttpStream(IDictionary pRequestParams, HttpWebRequest httpRequest)
{
string httpRequestDocument = (string)pRequestParams["RequestString"];
StreamWriter httpStreamWriter;
if ((httpRequestDocument == null) || (httpRequestDocument == String.Empty))
{
throw new Exception("No document to send");
}
httpRequest.Method = "POST";
httpRequest.ContentLength = httpRequestDocument.Length;
httpStreamWriter = new StreamWriter(httpRequest.GetRequestStream());
httpStreamWriter.Write(httpRequestDocument);
}
I should at least receive the 500 error code, but I time-out.
I could also use a tutorial on programmatically send a document via the HTTP POST method, if anyone know of any.
tx
|
|
|
|
|
I had to close the request stream
|
|
|
|
|
HI All,
I am trying to authenticate my username password using Advapi32.dll with function LogonUser. I am passing my Username and Password and domain and all things which need to pass in this function. But I am always getting false from this function. I am using windows 2000 Prof. and i have installed microsoft visual studio .net 2002 on my system.
One strainge thing is this exe is running on XP box very nicely. So any body tell me what could be the problem?
thanks,
Sharad
My code is:
-------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices; // DllImport
using System.Security.Principal; // WindowsImpersonationContext
using System.Security.Permissions; // PermissionSetAttribute
namespace Impersonate
{
// group type enum
public enum SECURITY_IMPERSONATION_LEVEL : int
{
SecurityAnonymous = 0,
SecurityIdentification = 1,
SecurityImpersonation = 2,
SecurityDelegation = 3
}
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
// obtains user token
[DllImport("advapi32.dll", SetLastError=true)]
public static extern bool LogonUser(string pszUsername, string pszDomain, string pszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
// closes open handes returned by LogonUser
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
// creates duplicate token handle
[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblCurrentUser;
private System.Windows.Forms.TextBox textBoxUsername;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxPassword;
private System.Windows.Forms.Button buttonLogon;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBoxDomain;
private System.Security.Principal.WindowsIdentity newwinid;
private System.Security.Principal.WindowsImpersonationContext newUser;
private System.Windows.Forms.Button buttonRevert;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
// set logged on username
lblCurrentUser.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// populate logon domain name
string sTempUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (sTempUser.IndexOf("\\") != -1)
{
string[] aryUser = new String[2];
char[] splitter = {'\\'};
aryUser = sTempUser.Split(splitter);
textBoxDomain.Text = aryUser[0];
}
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.lblCurrentUser = new System.Windows.Forms.Label();
this.textBoxUsername = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.buttonLogon = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.textBoxDomain = new System.Windows.Forms.TextBox();
this.buttonRevert = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Running As:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lblCurrentUser
//
this.lblCurrentUser.Location = new System.Drawing.Point(112, 24);
this.lblCurrentUser.Name = "lblCurrentUser";
this.lblCurrentUser.Size = new System.Drawing.Size(200, 16);
this.lblCurrentUser.TabIndex = 1;
//
// textBoxUsername
//
this.textBoxUsername.Location = new System.Drawing.Point(112, 80);
this.textBoxUsername.Name = "textBoxUsername";
this.textBoxUsername.Size = new System.Drawing.Size(144, 20);
this.textBoxUsername.TabIndex = 2;
this.textBoxUsername.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 3;
this.label2.Text = "New Username:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 104);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 5;
this.label3.Text = "New Password:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBoxPassword
//
this.textBoxPassword.Location = new System.Drawing.Point(112, 104);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.PasswordChar = '*';
this.textBoxPassword.Size = new System.Drawing.Size(144, 20);
this.textBoxPassword.TabIndex = 4;
this.textBoxPassword.Text = "";
//
// buttonLogon
//
this.buttonLogon.Location = new System.Drawing.Point(181, 136);
this.buttonLogon.Name = "buttonLogon";
this.buttonLogon.TabIndex = 6;
this.buttonLogon.Text = "Logon";
this.buttonLogon.Click += new System.EventHandler(this.buttonLogon_Click);
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 56);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(88, 16);
this.label4.TabIndex = 8;
this.label4.Text = "Logon Domain:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBoxDomain
//
this.textBoxDomain.Location = new System.Drawing.Point(112, 56);
this.textBoxDomain.Name = "textBoxDomain";
this.textBoxDomain.Size = new System.Drawing.Size(144, 20);
this.textBoxDomain.TabIndex = 7;
this.textBoxDomain.Text = "";
//
// buttonRevert
//
this.buttonRevert.Enabled = false;
this.buttonRevert.Location = new System.Drawing.Point(104, 136);
this.buttonRevert.Name = "buttonRevert";
this.buttonRevert.TabIndex = 9;
this.buttonRevert.Text = "Revert";
this.buttonRevert.Click += new System.EventHandler(this.buttonRevert_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(312, 189);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonRevert,
this.label4,
this.textBoxDomain,
this.buttonLogon,
this.label3,
this.textBoxPassword,
this.label2,
this.textBoxUsername,
this.lblCurrentUser,
this.label1});
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Impersonation Example";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void buttonLogon_Click(object sender, System.EventArgs e)
{
if (textBoxUsername.Text != "" && textBoxPassword.Text != "")
{
try
{
// attempt to impersonate specified user
newUser = this.ImpersonateUser(textBoxUsername.Text, textBoxDomain.Text, textBoxPassword.Text);
// update the running as name
lblCurrentUser.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
buttonRevert.Enabled = true;
buttonLogon.Enabled = false;
}
catch (Exception ex)
{
// why did it fail?
MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
MessageBox.Show(this, "Complete all the logon credentials", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
///
/// Revert back to previous user
///
private void buttonRevert_Click(object sender, System.EventArgs e)
{
// revert to previous user
newUser.Undo();
buttonRevert.Enabled = false;
buttonLogon.Enabled = true;
// update the running as name
lblCurrentUser.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
///
/// Attempts to impersonate a user. If successful, returns
/// a WindowsImpersonationContext of the new users identity.
///
/// <param name="sUsername" />Username you want to impersonate
/// <param name="sDomain" />Logon domain
/// <param name="sPassword" />User's password to logon with
/// <returns>
public WindowsImpersonationContext ImpersonateUser(string sUsername, string sDomain, string sPassword)
{
// initialize tokens
IntPtr pExistingTokenHandle = new IntPtr(0);
IntPtr pDuplicateTokenHandle = new IntPtr(0);
pExistingTokenHandle = IntPtr.Zero;
pDuplicateTokenHandle = IntPtr.Zero;
// if domain name was blank, assume local machine
if (sDomain == "")
sDomain = System.Environment.MachineName;
try
{
string sResult = null;
const int LOGON32_PROVIDER_WINNT50 = 2;
// create token
const int LOGON32_LOGON_NEW_CREDENTIALS = 4;
//const int SecurityImpersonation = 2;
// get handle to token
bool bImpersonated = LogonUser(sUsername, sDomain, sPassword,
LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_WINNT50, ref pExistingTokenHandle);
// did impersonation fail?
if (false == bImpersonated)
{
int nErrorCode = Marshal.GetLastWin32Error();
sResult = "LogonUser() failed with error code: " + nErrorCode + "\r\n";
// show the reason why LogonUser failed
MessageBox.Show(this, sResult, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// Get identity before impersonation
sResult += "Before impersonation: " + WindowsIdentity.GetCurrent().Name + "\r\n";
bool bRetVal = DuplicateToken(pExistingTokenHandle, (int)SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, ref pDuplicateTokenHandle);
// did DuplicateToken fail?
if (false == bRetVal)
{
int nErrorCode = Marshal.GetLastWin32Error();
CloseHandle(pExistingTokenHandle); // close existing handle
sResult += "DuplicateToken() failed with error code: " + nErrorCode + "\r\n";
// show the reason why DuplicateToken failed
MessageBox.Show(this, sResult, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
else
{
// create new identity using new primary token
WindowsIdentity newId = new WindowsIdentity(pDuplicateTokenHandle);
WindowsImpersonationContext impersonatedUser = newId.Impersonate();
// check the identity after impersonation
sResult += "After impersonation: " + WindowsIdentity.GetCurrent().Name + "\r\n";
MessageBox.Show(this, sResult, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
return impersonatedUser;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
// close handle(s)
if (pExistingTokenHandle != IntPtr.Zero)
CloseHandle(pExistingTokenHandle);
if (pDuplicateTokenHandle != IntPtr.Zero)
CloseHandle(pDuplicateTokenHandle);
}
}
}
}
|
|
|
|
|
Hi,
Actully I'm facing the same problem you've got! I think the domain paramter must take the name of the PC the file is in, not the name of domain or DC. This has nothing to do with Server! it's about connecting to a file in a PC, I thinks this is it!!
If you found the solution for that please send me it:
rami@raypub.com
|
|
|
|
|
Hi,
did you get a solution for this issue?
Jassim Rahma
|
|
|
|
|
No, not yet...
I'm using know a very stupid way: net.exe!!
|
|
|
|
|
I'm use an OleDbDataReader variable for get data from OLAP cube. I want show this data to DataGrid control, but I don't know a way. Can you help me?
Thanks.
|
|
|
|
|
here's an example of adding data from a database to a datagrid ( using an OleDbConnection )
VbCode:
<font color="blue">Private</font> <font color="blue">Sub</font> Button1_Click(<font color="blue">ByVal</font> sender <font color="blue">As</font> System.Object, <font color="blue">ByVal</font> e <font color="blue">As</font> System.EventArgs) <font color="blue">Handles</font> Button1.Click <br> <font color="blue">Dim</font> strConnection <font color="blue">As</font> <font color="blue">String</font> = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:/bin.mdb" <br> <font color="blue">Dim</font> strCommand <font color="blue">As</font> <font color="blue">String</font> = "SELECT * FROM binFrm" <br> OpenAccess(strConnection, strCommand) <br> <font color="blue">End</font> <font color="blue">Sub</font> <br> <br> <font color="blue">Public</font> <font color="blue">Function</font> OpenAccess(<font color="blue">ByVal</font> strConn <font color="blue">As</font> <font color="blue">String</font>, <font color="blue">ByVal</font> strComm <font color="blue">As</font> <font color="blue">String</font>) <br> <font color="blue">Dim</font> DBCon <font color="blue">As</font> <font color="blue">New</font> OleDbConnection(strConn) <br> DBCon.Open() <br> <font color="blue">Dim</font> DBCommand <font color="blue">As</font> <font color="blue">New</font> OleDbCommand(strComm, DBCon) <br> <font color="blue">Dim</font> DBAdapt <font color="blue">As</font> OleDbDataAdapter <font color="DarkGreen"><br></font> DBAdapt = <font color="blue">New</font> OleDbDataAdapter(DBCommand) <br> <font color="blue">Dim</font> DBset <font color="blue">As</font> <font color="blue">New</font> DataSet() <br> DBAdapt.Fill(DBset, "binFrm") <br> DataGrid1.DataSource = DBset.Tables("binFrm") <font color="DarkGreen">'///add the tabel "binfrm" to the datagrid <br></font> DBCon.Close() <br> DBCommand.Dispose() <br> DBAdapt.Dispose() <br> DBset.Dispose() <br> <font color="blue">End</font> <font color="blue">Function</font> <br>
not sure if that's what your after , but hope it helps
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
oops that the vb.net version lol , i'll try to bung a C# version together
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|