|
Create it as a WebControl... Windows and the web don't use the same stuff, so you'll have to wrap the functional parts of the application with web stuff.
|
|
|
|
|
Jasmine2501,
Are you saying that i would need to re-create the whole app again using WebControls?, i dont quite understand what you mean by "wrap the functional parts".
I know this is possible, as a company i worked for used to embed c# windows controls in web pages, but i never worked on how they did it.
Regards,
Gareth.
|
|
|
|
|
I found this: http://aspnet.4guysfromrolla.com/articles/052604-1.aspx[^][^]
But am having trouble displaying the control, i just get a red x.
<object id="LoginControl" height="255" width="337" classid="http:UNet.Manager.dll#UNet.Manager.Login.LoginControl"><br />
<param name="LoginControl" value="LoginControl"><br />
</param></object>
Regards,
Gareth.
|
|
|
|
|
Solved it.
Regards,
Gareth.
|
|
|
|
|
FTA:
"Hosting a Windows Control in ASP.NET has several limitations worth discussing. First it requires both that the client machines have, at minimum, the .NET redistributable installed and be browsing with Internet Explorer 5.01 or later. While this may work for a corporate intranet, it is not feasible for a public Internet application."
That makes it worthless for me. I don't like to alienate the users smart enough to use Firefox.
|
|
|
|
|
Jasmine2501,
Well since i am developing a prototype which will only ever be used by 1 person, that point isn't valid.
Regards,
Gareth.
|
|
|
|
|
I want user to enter A-Z or 0-9 only. what's wrong with this
RegularExpressions.Regex reg = new RegularExpressions.Regex("[a-zA-Z0-9]");
if i enter :hello or _hello or !hello it says it's valid but its not
if (reg.IsMatch(textfield1.Text))
{
}
Thanks for helping me out in advance
|
|
|
|
|
You need to say that it must match at the begining and end with ^ and $ and you need to allow 1 or more matches with +
^[a-zA-Z0-9]+$
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I have a class class1, which has a constructor and one method:
public class1(TextReader tr)
{
InitFromTextReader(tr);
}
protected virtual bool InitFromTextReader(TextReader tr)
{
}
It has subclass class1_1 , which also has a subclass class1_1_1 .
These two classes both override InitFromTextReader .
The text stream I am reading has class names embedded in it, just before the data for the object. So I read the class name, get the Type object for it and ask for the constructor that takes a TextReader as it's one and only parameter.
GetConstructor is not finding that constructor for the subclasses. I used GetConstructors , and it just does not exist.
So, all that to ask:
Even though they do not do a dang thing, do I need to write constructors
public class1_1(TextReader tr)
: base(tr)
{
} and
public class1_1_1(TextReader tr)
: base(tr)
{
}
so that I can find them with GetConstructor ?
It this kind of thing wot causes unrest!
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|
|
Yes you would need to implement the constructors in your derived classes. The base constructor only constructs the base object. Really you don't need the InitFromTextReader because you should be able to perform the initialization in the constructors (which pass the TextReader to it's base class).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks, I appreciate the quick response, but I was afraid of that.
I needed the InitFromTextReader anyway, as I do not just use it from the constructor.
So what it comes down to is you can not implicitly inherit a constructor's capabilities in c#:
To access the capability, you must override it to explicitly expose it, even if there is no other functionality added.
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|
|
Correct.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
I know how to resize one dimensional array,
Array.Resize(ref ArrayName, newSize)
But if my array is of 2 dimension, how can i resize to new 2 dimension ?
|
|
|
|
|
Is it a real two dimensional array or a jagged array?
two dimensional:
object [,] myArray = new object[X,Y];
jagged array
object [][] myArray = new object[X][];
foreach (object[] myObject in myArray)
{
myObject = new object[Y];
}
A two dimensional array is X * Y in size if you read the length, where an jagged array is just X with a Y value of each X.
|
|
|
|
|
thanks
My array is real two dimensional array.
string [,] = new string[2,4];
Now, I want to resize this array to new value of string[7,9] but I dont find any way to do this.
|
|
|
|
|
What you may need to do, ugly as it is, is create a new one of the new size, and copy it in.
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|
|
Oh, far as I'm aware that is what you HAVE to do for a multidimensional array.
Jagged array's are normally the "defacto" standard because of this...
I guess you could make something like this:
object[,] ResizeTwoDimArray(object[,] oldObject, uint x, uint y)
{
object[,] newObject = new object[x,y];
Array.Copy(oldObject,newObject,oldObject.Length);
return newObject;
}
|
|
|
|
|
You can't resize an array in .NET. The Array.Resize method creates a new array and copies the data to it.
That is what you have to do to resize a two dimensional array too, only there is no built in method for it so you have to do it yourself.
If you frequently resize the array, you should consider using a dynamic collection instead that actually supports resizing, like an list of arrays or a list of lists.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hello, I wrote a windows service that is supposed to start an interactive GUI app. I realize a service will not readily do this so I've pieced together the code below to bypass that. However, the call to CreateProcessAsUser always returns a 1314 error: 'A required privilege is not held by the client.'
I realize from the doc's that the calling process must have SE_TCB_NAME privilege to assign new privileges to the new process and I have done that in a method further below.
So I'm not sure why this is not launching the app. To keep things simple, I'm running notepad.exe from a cmd console, I'm just running this code as its own app so there's no service on top to muddle things up. Also I'm running it locally to make things simpler, but still that error keeps popping up. Also I'm on XP.
Can anyone see what I have done wrong in my code? Thanks in advance!!
public static void Main(string[] args)
{
IntPtr tokenHandle = new IntPtr(0);
IntPtr dupeTokenHandle = new IntPtr(0);
try
{
string userName, domainName;
domainName = "mydomain";
userName = "user";
pwd="mypass";
tokenHandle = IntPtr.Zero;
dupeTokenHandle = IntPtr.Zero;
bool returnValue = LogonUser(userName, domainName, pwd,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if(false == returnValue)
{
int ret = Marshal.GetLastWin32Error();
Console.WriteLine("LogonUser failed with error code : {0}", ret);
int errorCode = 0x5;
throw new System.ComponentModel.Win32Exception(errorCode);
}
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
pSec.nLength = Marshal.SizeOf(pSec);
tSec.nLength = Marshal.SizeOf(tSec);
bool retVal = DuplicateTokenEx(tokenHandle, (uint)TokenAccessLevels.AllAccess, ref pSec,
SECURITY_IMPERSONATION_LEVEL.SecurityIdentification, TOKEN_TYPE.TokenPrimary,
out dupeTokenHandle);
if(false == retVal)
{
CloseHandle(tokenHandle);
Console.WriteLine("Exception thrown in trying to duplicate token.");
return;
}
WindowsIdentity newId = new WindowsIdentity(dupeTokenHandle);
WindowsImpersonationContext impersonatedUser = newId.Impersonate();
PROFILEINFO aPI = new PROFILEINFO();
aPI.dwSize = 32;
aPI.lpUserName = WindowsIdentity.GetCurrent().Name;
bool retLoadProfile = LoadUserProfile(newId.Token, ref aPI);
StringBuilder CommandLine = new StringBuilder(@"cmd /c C:\windows\system32\notepad.exe");
const uint NORMAL_PRIORITY_CLASS = 0x0020;
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
STARTUPINFO sInfo = new STARTUPINFO();
IntPtr aToken=newId.Token;
SetPrivs(ref aToken);
sInfo.wShowWindow = 5;
sInfo.lpTitle = "Hello!";
sInfo.lpDesktop="winsta0\\default";
uint dwCreationFlags = NORMAL_PRIORITY_CLASS| CREATE_NEW_CONSOLE;
IntPtr pEnv = IntPtr.Zero;
if(CreateEnvironmentBlock(out pEnv, dupeTokenHandle, true))
{
dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
}
else
{
pEnv = IntPtr.Zero;
}
bool retCreateProcess = CreateProcessAsUser(newId.Token,
null,
CommandLine,
ref pSec,
ref tSec,
false,
NORMAL_PRIORITY_CLASS,
pEnv,
null,
ref sInfo,
out pInfo);
int err = Marshal.GetLastWin32Error();
Console.WriteLine("CreateProcess="+retCreateProcess.ToString()+". With error:"+ err.ToString());
Console.WriteLine("After impersonation: " + WindowsIdentity.GetCurrent().Name);
Console.ReadKey();
impersonatedUser.Undo();
if(tokenHandle != IntPtr.Zero)
CloseHandle(tokenHandle);
if(dupeTokenHandle != IntPtr.Zero)
CloseHandle(dupeTokenHandle);
}
catch(Exception ex)
{
Console.WriteLine("Exception occurred. " + ex.Message);
}
}
}
In this method as an experiment I tried setting all privileges to see if perhaps I had been missing one but generally I will be setting TCB(if that's the right one to set.)
You'll note that I'm setting the Current Process Privilage to TCB because the Doc's say that that needs to be done.
private static bool SetPrivs(ref IntPtr theToken)
{
const int SE_PRIVILEGE_ENABLED = 0x0002;
List<string> aPrivs = new List<string>();
aPrivs.Add(SE_CREATE_TOKEN_NAME);
aPrivs.Add(SE_ASSIGNPRIMARYTOKEN_NAME);
aPrivs.Add(SE_LOCK_MEMORY_NAME);
aPrivs.Add(SE_INCREASE_QUOTA_NAME);
aPrivs.Add(SE_UNSOLICITED_INPUT_NAME);
aPrivs.Add(SE_MACHINE_ACCOUNT_NAME);
aPrivs.Add(SE_TCB_NAME);
aPrivs.Add(SE_SECURITY_NAME);
aPrivs.Add(SE_TAKE_OWNERSHIP_NAME);
aPrivs.Add(SE_LOAD_DRIVER_NAME);
aPrivs.Add(SE_SYSTEM_PROFILE_NAME);
aPrivs.Add(SE_SYSTEMTIME_NAME);
aPrivs.Add(SE_PROF_SINGLE_PROCESS_NAME);
aPrivs.Add(SE_INC_BASE_PRIORITY_NAME);
aPrivs.Add(SE_CREATE_PAGEFILE_NAME);
aPrivs.Add(SE_CREATE_PERMANENT_NAME);
aPrivs.Add(SE_BACKUP_NAME);
aPrivs.Add(SE_RESTORE_NAME);
aPrivs.Add(SE_SHUTDOWN_NAME);
aPrivs.Add(SE_DEBUG_NAME);
aPrivs.Add(SE_AUDIT_NAME);
aPrivs.Add(SE_SYSTEM_ENVIRONMENT_NAME);
aPrivs.Add(SE_CHANGE_NOTIFY_NAME);
aPrivs.Add(SE_REMOTE_SHUTDOWN_NAME);
aPrivs.Add(SE_UNDOCK_NAME);
aPrivs.Add(SE_SYNC_AGENT_NAME);
aPrivs.Add(SE_ENABLE_DELEGATION_NAME);
aPrivs.Add(SE_MANAGE_VOLUME_NAME);
aPrivs.Add(SE_IMPERSONATE_NAME);
aPrivs.Add(SE_CREATE_GLOBAL_NAME);
SetCurrProcPriv(SE_TCB_NAME);
foreach(string aPriv in aPrivs)
{
TOKEN_PRIVILEGES aTP = new TOKEN_PRIVILEGES();
LUID luid = new LUID();
aTP.PrivilegeCount = 1;
aTP.Privileges = new int[3];
aTP.Privileges[2] = SE_PRIVILEGE_ENABLED;
aTP.Privileges[1] = luid.HighPart;
aTP.Privileges[0] = luid.LowPart;
try
{
LookupPrivilegeValue(IntPtr.Zero, aPriv, ref luid);
bool isSuccess=AdjustTokenPrivileges(theToken, false, ref aTP, Marshal.SizeOf(aTP), IntPtr.Zero, IntPtr.Zero);
if(!isSuccess)
return false;
else
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
return false;
}
private static IntPtr SetCurrProcPriv(string thePrivilegeName)
{
IntPtr hToken =new IntPtr();
bool isSuccess=false;
LUID luid = new LUID();
IntPtr aCurrProc = GetCurrentProcess();
TOKEN_PRIVILEGES aTP=new TOKEN_PRIVILEGES();
STARTUPINFO si=new STARTUPINFO();
si.cb = (int)Marshal.SizeOf(si);
isSuccess = OpenProcessToken(aCurrProc,
TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES |
TOKEN_ADJUST_SESSIONID |TOKEN_ADJUST_DEFAULT |
TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE, out hToken);
if(!isSuccess)
Console.WriteLine("Error OpenProcessToken " + Marshal.GetLastWin32Error().ToString());
isSuccess = LookupPrivilegeValue(IntPtr.Zero, thePrivilegeName, ref luid);
if(!isSuccess)
Console.WriteLine("Error OpenProcessToken " + Marshal.GetLastWin32Error().ToString());
aTP.PrivilegeCount = 1;
aTP.Privileges = new int[3];
aTP.Privileges[0] = luid.LowPart;
aTP.Privileges[1] = luid.HighPart;
aTP.Privileges[2] = SE_PRIVILEGE_ENABLED;
isSuccess = AdjustTokenPrivileges(hToken, false, ref aTP, Marshal.SizeOf(aTP), IntPtr.Zero, (IntPtr)Marshal.SizeOf(aTP));
if(!isSuccess)
return IntPtr.Zero;
else
return hToken;
}
</string></string>
PhrankBooth
|
|
|
|
|
Did you try this[^]?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
This is how I am opening an excel spreadsheet.
But when it is opened, I do not see the addins
Is there a parameter to set to leave the addins as it is?
Microsoft.Office.Interop.Excel.Application EApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Worksheet WS = ((Microsoft.Office.Interop.Excel.Worksheet)(EApp.Workbooks.Open(@"C:\Data.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing).ActiveSheet));
EApp.Visible = true;
|
|
|
|
|
Hi
I have to read all the link lines in HTML file. If the links path is not already there, then append link. I have done like below but I could not append the link if I use my code.
StreamReader sr = File.OpenText(navigationFile);
String line = sr.ReadToEnd();
if (!(line.IndexOf(pubPath) > 1))
{
sr.Close();
using (StreamWriter sw = File.AppendText(navigationFile))
{
sw.WriteLine("
");
sw.WriteLine("");
sw.WriteLine(pubTitle);
sw.WriteLine("");
sw.Close();
}
Does any one have Idea about it.
thanks.
|
|
|
|
|
Are any changes being appended to the file? Are any exceptions being thrown?
From your code, you are appending pubTitle, not pubPath (which is the one you are searching for).
Also, you should probably use the String.Contains[^] method. Like so:
if (!line.Contains(pubPath)) {
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi Tom,
thank you very much for your reply. I missed the anchor tags before and after the pubtitle while uploading the post. I have looked for Contains(), I dont have Contains() for String.
Is there any other way.
|
|
|
|
|
Are you using .Net 1.x? Contains is supported in .NET Framework 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0.
But you can use String.IndexOf[^], like you had before. But you should be checking for -1, because 0 and all positive integers indicates that it found the string.
if (-1 == line.IndexOf(pubPath)) {
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|