|
I'm having trouble with getting the display name of my folder via my PIDL. I know the methods work, as they run without error, and everything proceeds almost exactly as expected. However, the STRRET structure that is filled by the GetDisplayNameOf() method gains a pointer in it's union type, however, the type value used to determine what type the STRRET uses, is always set to zero after the method.
mySTRRET = new STRRET();<br />
result = myShellFolder.GetDisplayNameOf(relativePIDL,SHGDN_Flags.SHGDN_NORMAL | SHGDN_Flags.SHGDN_FORPARSING<br />
,ref mySTRRET);
Now, i've managed to pull a string out of the StretToStr method by converting the string to a pointer, and then converting it back to a string once it's been processed - Does anyone know why this works yet my string ref failed to do anything with my string?
myFileName = new string(' ',128);<br />
myFileName += "\0";<br />
<br />
IntPtr myFileNamePointer = Marshal.StringToHGlobalAuto(filePath);<br />
result = COMStuff.StrRetToStr(ref mySTRRET, desktopPIDL, ref myFileNamePointer);<br />
myFileName = Marshal.PtrToStringAuto(myFileNamePointer);
The string I get however, is the full StretToStr file path, so i'm a bit baffled. This probably has something to do with the zero type value. If I manualy set the STRRET value, i get odd results.
Value 1 - Gibberish string of unknown charachters and parenthesis.
Value 2 - "~--*square*" (Square Being the unknown charachter type thing)
Value 3 - null
Can anyone shed any light on this?
Cheers
Cata
|
|
|
|
|
Does anyone have a textbox based control that will only accept valid URLs?
camasmartin
hobby programmer
|
|
|
|
|
Handle the Validating even on a TextBox (or override OnValidating if deriving from TextBox ) and in your validation code, use a Regex instance to check the URL, setting CancelEventArgs.Cancel to true if the regular expression fails.
The regular expression you use is determined by what "URL"s you want to support. The concept of URLs - which is a form of URI - is very vague. Any protocol scheme is allows, though they might not match any protocol handlers. Common schemes are http(s), ftp(s), nntp, news, mailto, gopher, and telnet. Windows adds some (depending on what's installed) like ms-help, its, and some others. You can add them to Mozilla/Netscape, too. And each of these can have slightly different syntax that others don't support.
My advice - unless you want several regular expressions that will slow validation tremendously, just use the Uri class like so:
public class UrlBox : TextBox
{
protected override void OnValidating(CancelEventArgs e)
{
try
{
new Uri(this.Text);
}
catch
{
e.Cancel = true;
}
}
} This should handle most variants of URLs.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you.
With some tuning, it will come close enough.
I didn't know about the Uri class.
camasmartin
hobby programmer
Learning every day
|
|
|
|
|
I have an outlookbar with a bunch of items in it. when u click an item, it calls the event called outlookClickAction
outlookBar = new LumiSoft.UI.Controls.WOutlookBar.WOutlookBar();<br />
outlookBar.ItemClicked += new ItemClickedEventHandler(outlookClickAction);<br />
<br />
private void outlookClickAction(object sender, LumiSoft.UI.Controls.WOutlookBar.ItemClicked_EventArgs e)<br />
{<br />
...<br />
}
The problem is, i dont know how to tell the event handler which item was clicked. All i need to be able to do is tell the event handler the text of the item that was clicked. if u have any idea how to do this, please help. Thanks.
By BigBlob202
Dinco Inc.
|
|
|
|
|
check sender.text it might already be there for you. I havn't worked with outlookbars but it works with toolbars and menubars...
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
sender.text didnt work but thanks anyway because that led me on to test some other stuff and i finally got it to work. in case anyone else wants to know, all you do is use e.Item.Caption . Thank You!
By BigBlob202
Dinco Inc.
|
|
|
|
|
I have created a control which main class (with attributes) is:
[DefaultProperty("Text"),ToolboxData("<{0}:MioCmd runat=server>"),
ParseChildren(ChildrenAsProperties = false),
ControlBuilderAttribute(typeof(MioCmd.MioBuilder)),
Designer("MioCmd.MioDesigner, MioCmd"),
PersistChildren(false)]
public class MioCmd : WebControl, INamingContainer{
...
}
into MioCmd I have an attribute with this declaration:
[Bindable(false),
Description("Imposta i comandi dell'editor."),
NotifyParentProperty(false),
RefreshProperties(RefreshProperties.All),
PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public ComandiCollection Comandi{
set{this.objComandi = value;}
get{return this.objComandi;}
}
the type of this attribute is derived from ControlCollection and the class has this declaration:
public class ComandiCollection : ControlCollection, IEnumerable{
...
}
ComandiCollection is a Collection of child controls of type Comando which inherits from Control:
[DefaultProperty("CommandId"), Bindable(false)]
public class Comando : Control{
...
}
My problem is that everytime I try to change the property Comandi through Visual Studio collection editor I'm not able to Add/Remove elements (the two buttons are disabled!!!) and every change that I made Isn't visible in the main window by now, but It is visible only after switching from visual editor to code editor and back to visual editor...
I really don't know how to solve this problem...do I have to change architecture or do I have to made some little changes?...if you have an Idea please help me!!!
ciao
Alessandro Angelotti
MKTG Street Srl
aleang72@hotmail.com
|
|
|
|
|
First, you don't need to implement IEnumerable in your ComandiCollection . Since it derives from ControlCollection , it already implements IEnumerable . It won't hurt anything - it just doesn't look good.
The first thing that comes to mind when looking at your code is that you don't specify the template which dictates how the control collection is persisted as nested elements. See the documentation and related links for the PersistenceMode enumeration[^] in the .NET Framework SDK for an example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
I posted this on the ASP.NET forum, but have gotten no responses, so I figured I'd ask here now (the code is c# after all...so it's kinda on-topic)
Apparently I don't know jack about impersonation in ASP.NET. I need to have ASP.NET look at a network share and tell me if it finds a file. My code looks like:
<br />
int i;<br />
bool b=LogonUser("someuser","RESTEKCORP","thepassword",3,0,out i );<br />
WindowsIdentity wi = new WindowsIdentity (new System.IntPtr (i));<br />
WindowsImpersonationContext wic = wi.Impersonate ();<br />
FileInfo FI = new FileInfo (@"\\10.238.218.XXX/some_share/TheFile.ext");<br />
Now my confussion: I know "someuser" has access to the share, since I use my own login (at least for now) and I can list the directory and edit files through windows. The login seems to succeed, as b is true .
But FI.Exists comes back as false , even though I know the file exists.
So I look at FI in the debugger and notice that I am getting a message saying that a System.UnauthorizedAccessException occured. Which suggests to me that the impersonation is not working...
What am I missing?
Thanks in advance,
Bill
|
|
|
|
|
Several possibilities. First off, is your impersonation succeeding?
1. Is the ASPNet account set to run as part of the OS? It will need to be, and remember that authentication in a web app is different than logging on locally.
2. I'm not certain what a value of 3 means for LogonType in LogonUser call - I assume it means NETWORK logon, which doesn't create a primary token handle, required for impersonation - should be using INTERACTIVE logon (2).
3. No token is being provided when you create your WindowsIdentity.
4. It may only be in your example, but aren't the forward slashes in the path supposed to be backslashes?
5. Is this running on/against XP or 2000? There are documented issues with getting impersonation to work under 2000 without hacking security to do it.
Hope this helps.
Example I got to work on XP (example hints came directly from MSDN, BTW):
using System;
using System.Security;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security.Permissions;
namespace ConsoleApplication2
{
class Class1
{
[DllImport("advapi32.dll", SetLastError=true)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private unsafe static extern int FormatMessage(int dwFlags, ref IntPtr lpSource,
int dwMessageId, int dwLanguageId, ref String lpBuffer, int nSize, IntPtr *Arguments);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);
public unsafe static string GetErrorMessage(int errorCode)
{
int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
int messageSize = 255;
String lpMsgBuf = "";
int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
IntPtr ptrlpSource = IntPtr.Zero;
IntPtr prtArguments = IntPtr.Zero;
int retVal = FormatMessage(dwFlags, ref ptrlpSource, errorCode, 0, ref lpMsgBuf, messageSize, &prtArguments);
if (0 == retVal)
{
throw new Exception("Failed to format message for error code " + errorCode + ". ");
}
return lpMsgBuf;
}
[STAThread]
static void Main(string[] args)
{
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
const int SecurityImpersonation = 2;
IntPtr token = new IntPtr(0);
IntPtr dupToken = new IntPtr(0);
bool result = LogonUser("frog", "pond", "ribbit", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token);
if(result == false)
{
Console.WriteLine("Failed to log on.");
Console.ReadLine();
return;
}
bool dupResult = DuplicateToken(token, SecurityImpersonation, ref dupToken);
if(dupResult == false)
{
Console.WriteLine("Failed to log on.");
Console.ReadLine();
return;
}
WindowsIdentity newId = new WindowsIdentity(dupToken);
Console.WriteLine("Impersonation starting. Windows ID name before = " + WindowsIdentity.GetCurrent().Name);
WindowsImpersonationContext impersonatedUser = newId.Impersonate();
Console.WriteLine("Impersonation complete. Windows ID name after Impersonate = " + WindowsIdentity.GetCurrent().Name);
impersonatedUser.Undo();
Console.WriteLine("Impersonation undone. Windows ID name after Undo = " + WindowsIdentity.GetCurrent().Name);
Console.ReadLine();
}
}
}
Hope this helps...
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi there
I have a problem in using a data table object created from a dataset object.
I have a form that has the following controls:
2 textboxs : txtTodayEvents , txtTodayDescr
1 listbox : lbToday
1 label : lblToday
The database i am using has the following fields:
ID
EventName
Description
EventDate
This is the code that i am using to get my data table working:
private void TodaysEvents()
{
DataSet dsAllEvents = new DataSet("Events");
dsAllEvents.ReadXml("EventsDB.xml");
string date = DateTime.Now.ToShortDateString();
int todEve = dsAllEvents.Tables["Events"].Select("EventDate Like '*" + date + "*'").Length;
if(todEve>=1)
{
DataTable TodTable = new DataTable("TE");
TodTable.Columns.Add("ID",System.Type.GetType("System.String"));
TodTable.Columns.Add("EventName",System.Type.GetType("System.String"));
TodTable.Columns.Add("Description");
TodTable.Columns.Add("EventDate",System.Type.GetType("System.String"));
TodTable.Rows.Add(dsAllEvents.Tables["Events"].Select("EventDate Like '*" + date + "*'"));
lbToday.DataSource = TodTable;
lbToday.DisplayMember = "EventDate";
lbToday.Visible = true;
txtTodayEvent.DataBindings.Add("Text",TodTable,"EventName");
txtTodayEvent.Visible = true;
txtTodayDescr.DataBindings.Add("Text",TodTable,"Description");
txtTodayDescr.Visible = true;
}
else
{
lblToday.Visible = true;
}
}
when i run this code it runs but i get nothing in my controls
Can anyone plz tell me what i am doing wrong?
VisionTec
|
|
|
|
|
I can't tell what data type you're using for EventDate in the "Events" DataTable, but if it's a DateTime it may be worthwhile to use a BETWEEN clause or >= and <= to compare dates (start at midnight, and end at 11:59:59, for instance) instead of LIKE.
The bigger issue is that a call to Datatable.Select returns an array of DataRow objects (DataRow[]) from 0 to n members in length, not an integer. That said, the lines that read:
int todEve = dsAllEvents.Tables["Events"].Select("EventDate Like '*" + date + "*'").Length;
if(todEve>=1)
should read something like:
DataRow[] foundRows = dsAllEvents.Tables["Events"].Select("EventDate Like '*" + date + "*'").Length;
if(foundRows.Length >= 1)
One more small note; instead of
System.Type.GetType("System.String")
you can shorthand with
typeof(string)
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi there
I have an icon that i use as:
my application's icon
my notifyicon's icon
and my main form's icon
its a 22kb icon.
now everything works fine but the size
of my app increases three times! (66kb)
when it should only have increased 22kb
how can i fix this problem or is this something normal?
VisionTec
|
|
|
|
|
Use only one instance of it, say from a static class:
public sealed class AppInfo
{
private AppInfo() {}
private static Icon AppIcon;
static AppInfo()
{
AppIcon = new Icon(typeof(AppInfo), "App.ico");
}
} This is a basic example, but should give you the idea.
You won't be able to use the same icon for the application (the icon that is at the first index in the PE/COFF executables .rsrc section), though. That's stored different than the "App.ico" (example) for which you should change the build action to "Embedded Resource".
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an outlook bar that can recieve drag drop operations. I'm trying to get it so that when u drag a shortcut from the desktop into the outlook bar, it will add an item and use the icon from the shortcut as the picture for the outlook bar menu item that it adds. Ive already got the drag drop stuff working, and it adds an item to the outlookbar, but i cant figure out how to get the icon from the shortcut. Any ideas??
By BigBlob202
My Site - I just started it so theres not much on it.
|
|
|
|
|
P/Invoke the SHCreateFileExtractIcon function and declare the IExtractIcon interface. You can find more information about these in the Platform SDK on MSDN Library online[^].
You can also P/Invoke SHGetFileInfo if you know you'll be receiving the path to a file with an associated icon. This won't work for executable files (i.e., to get the icon located at index 1 in the executable's .rsrc section). Search this thread's comments (click "Search comments" above) for SHGetFileInfo for previous discussions and sample code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
are there any examples of this, because i am confused. Please Help!
By BigBlob202
Dinco Inc.
|
|
|
|
|
As I mentioned the first time, why don't you search the comments of the C# forum for information on the SHGetFileInfo API? I've posted this code before. See Re: How do I find a file associated icon?[^]. This will work for files with file associations (files without associations will get the default icon).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
SetWindowPos(m_hWnd,(IntPtr)12,0,0,Screen.PrimaryScreen.Bounds.Width/2,Screen.PrimaryScreen.Bounds.Height/2,11);
it does not compile wrong but returns false
|
|
|
|
|
Besides the fact that you can do all this without P/Invoking calls (using Form.Location and Form.Size , which you should use for portability and ease), you didn't mention how you declared the P/Invoked method, which should look like:
[DllImport("user32.dll")]
private static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
[MarshalAs(UnmanagedType.SysInt)] int X,
[MarshalAs(UnmanagedType.SysInt)] int Y,
[MarshalAs(UnmanagedType.SysInt)] int cx,
[MarshalAs(UnmanagedType.SysInt)] int cy,
[MarshalAs(UnmanagedType.U4)] UINT uFlags); Pass the Form.Handle property value as the first parameter.
Honestly, though - just stick with the properties already available on the Form class (some of which are inherited from Control ). You don't need this function at all and will most likely break portability if you ever require it anyway.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
He's moving and positioning windows that don't belong to his app...
RageInTheMachine9532
|
|
|
|
|
but he realy does not do it
it always return false and dont resize or reposotion the window
There is another question
SWP_NOZORDER??
HWND_TOP??
how can i put these in the function
|
|
|
|
|
Find out what they're defined as in the Platform SDK headers.
private const int SWP_NOZORDER = 4;
private const int HWND_TOP = 0;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanx for ur time
but i dont want to move my app form but i am moving an outside app and try to resize it
There is another question
SWP_NOZORDER??
HWND_TOP??
how can i put these in the function
|
|
|
|
|