|
This will only work in a Windows Form, I've learned that much. I'm building WebForms, so I have to come up with different round-about ways to do things. Microsoft has never been known for being user and/or developer friendly.
Krisman
|
|
|
|
|
I doubt that, because I have used data binding in my web project.
Here's an excerpt of the code that I used:
cbApplication.DataSource = dsApplication.Tables(0)
cbApplication.DataTextField = "DirectoryName"
cbApplication.DataValueField = "IDDirectory"
cbApplication.DataBind()
Edbert P.
Sydney, Australia.
|
|
|
|
|
I'll have to try again. But I keep getting errors and our .Net gurus where I work (our network guys) said it's because I'm trying to use a Windows Forms functionality with a Web Form. But I'm also working without a Localhost because of the way .Net was installed on our systems and servers.
Krisman
|
|
|
|
|
I've been looking around the forums for hints on adding to the Windows context menu. I think I've figured it out reading eh Windows Shell programming guide. But I noticed i have install the DOSHere PowerToy some time ago, but I have never seen the DOS Here menu option in the Windows shell menu for directories. Does anyone know if XP no allows Context menu extensions for Directories anymore ?
here is the registry seetings for the DOS Here shel entry that does not show up:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell]
@="none"
[HKEY_CLASSES_ROOT\Directory\shell\DosHere]
@="Command &Prompt Here"
[HKEY_CLASSES_ROOT\Directory\shell\DosHere\command]
@="C:\\WINDOWS\\System32\\cmd.exe /k cd \"%1\""
I even tried my own but it didn't work
|
|
|
|
|
|
i know this sounds simple but can someone please tell me how i can draw boxes and circles to the printer
thanks
chad
|
|
|
|
|
Check out the PrintDocument and Graphics classes. Printing is essentially no different from drawing on a windows form, the medium is just different.
|
|
|
|
|
How can you lock a file in .NET? I have a windows application that reads xml files. If two users are trying to read the same file, I want to lock the file so the second user can't read or change the file.
I'm looking for the most bare bones lock and unlock functionality.
Thanks
|
|
|
|
|
The System.IO.FileStream can do this. Read the .NET Framework SDK for more information:
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
XmlTextReader reader = new XmlTextReader(stream);
try
{
}
finally
{
reader.Close();
stream.Close();
} This is a very simplistic example. Read about the FileStream constructor for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I just figured this out:
private bool LockFile( string sFilePathToLock )<br />
{<br />
bool bFileLocked = false;<br />
<br />
if( File.Exists( sFilePathToLock ) && ( File.GetAttributes( sFilePathToLock ) != FileAttributes.ReadOnly ) )<br />
{<br />
File.SetAttributes( sFilePathToLock, FileAttributes.ReadOnly );<br />
<br />
bFileLocked = true;<br />
}<br />
<br />
return bFileLocked;<br />
}<br />
<br />
private bool UnLockFile( string sFilePathToUnLock )<br />
{<br />
bool bFileUnLocked = false;<br />
<br />
if( File.Exists( sFilePathToUnLock ) && ( File.GetAttributes( sFilePathToUnLock ) == FileAttributes.ReadOnly ) )<br />
{<br />
File.SetAttributes( sFilePathToUnLock, FileAttributes.Normal );<br />
<br />
bFileUnLocked = true;<br />
<br />
}<br />
<br />
return bFileUnLocked;<br />
}
Hope this helps.
|
|
|
|
|
Although I'm a C# newbie, I can see Manster's solution will not work. See my (AS) comments below:
if( File.Exists( sFilePathToLock ) && ( File.GetAttributes( sFilePathToLock ) != FileAttributes.ReadOnly ) )<br />
{<br />
File.SetAttributes( sFilePathToLock, FileAttributes.ReadOnly );<br />
<br />
bFileLocked = true;<br />
}<br />
<br />
return bFileLocked;<br />
}
The original reply (to use FileStream) seems more like it, but you still need to trap the error when it fails to open the file because it is already locked.
|
|
|
|
|
This is not a correct solution. This only makes the file read-only to programs that check it. See my post for the correct solution, a solution that has been used for as long as filesystems have been around. This is the way it's supposed to be done and truly locks it while it's open from reading or writing by other processes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I want to protect my component so i followed the sample from Microsoft but i get always the LicenseException. I have to say that i don't know how to implement the part in the host application. That a part of the code of my component :
[LicenseProviderAttribute(typeof(LicFileLicenseProvider))]
public class Info: Component
{
private License license = null;
public Info()
{
license = LicenseManager.Validate(typeof(Info), this);
}
Thanks in advance
|
|
|
|
|
Read the documentation for LicFileLicenseProvider.GetLicense . The default LicFileLicenseProvider imlpementation looks for a file named myClass.lic, where myClass is the full name of the class. So, if you have a namespace like MyNamespace.MyClass , you must have a file in the same directory as your assembly that contains the component called MyNamespace.MyClass.lic. Inside that file you must include "MyNamespace.MyClass is a licensed component.".
Note, this LicenseProvider is meant only as an example. This is by no means secure and you should derive your own LicenseProvider to provide a more secure means of licensing your control.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want my program to open a postscript file and send Ctrl+C to ghostview,
this is part of my code:
Process.Start("gsview32.exe", openFileDialog.FileName);
SendKeys.Send("^c");
but I found ^c was sent to my own program not to ghostview,
someone told me I should use SetForegroundWindow to activate ghostview,
(like AppActivate in VB)
but I don't know how to give the parameter to SetForegroundWindow,
Can anyone give an simple example to activate my ghostview...??
Thanks a lot !!
|
|
|
|
|
You need window handle to use SetForeGroundWindow method.
You can the window handle using the FindWindow method.
HWND FindWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName);
you can give null to the lpClassName and give the Windows title to the
lpWindowName to find the Window handle.
BOOL SetForegroundWindow(HWND hWnd);
|
|
|
|
|
A much simpler way is to use the Process object that is returned from Process.Start and to use the Process.MainWindowHandle to the call for SetForegroundWindow :
Process p = Process.Start("gsview32.exe, openFileDialog.FileName);
if (p != null)
SetForegroundWindow(p.MainWindowHandle); Where SetForegroundWindow is defined as:
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for sssyed_in and Heath,
Finally I use Heath's method to solve my problem...
But then I have one new problem to ask:
How to set my own program back to ForegroundWindow...??
Thank you very much!!
|
|
|
|
|
Pass either your main Form 's Handle property (inherited from Control ) into SetForegroundWindow , or use Process.GetCurrentProcess().MainWindowHandle . The former is much quicker and recommended if possible.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Here's the issue :
I want to serialize some objects whose class contains a static attribute and I need to find this value again when I deserialize my objects.
For example :
[Serialize]<br />
public class MyObject<br />
{<br />
static int _NbInstances;<br />
string _Name;<br />
<br />
...<br />
}
How to make _NbInstances persistant ? Where should this value be saved ?
- Éric -
|
|
|
|
|
This is a conceptual no-no.
Static attributes should not be serialized with instances, because static attributes are not instance attributes. You can include these values by creating your custom serializer, but if you include these values in serialization, this will lead to inconsistent values, because every time you deserialize an instance, the static values will change.
A better design would be creating two methods, e.g. saveStatics() and readStatic() on each class that needs it.
BTW, a static "string _Name" smells bad design...
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
Hello Daniel,
I know what you mean and I don't want to serialize the static value WITH each instance, but I was thinking of a kind of "meta-serialization" for class (just as static constructors exist).
In fact I'd like to know which design is the best for that. But it has to be done manually.
Note that I've writen these three lines of code quickly just as an illustration because the complexity of a better code is useless for the question.
Thank you,
- Éric -
|
|
|
|
|
Well, in that case, I think that one interesting possibility would be: group your static properties into a Singleton class. Then, serialize this Singleton. This way, you can only mark the singleton [Serializable].
If you think about it, you may be missing a class on your design that is simply a singleton...
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
Hello,
Now I try to change default printer using C#.
After my investigation, I found it use WMI.
I used to WMI (Win32_Printer), but I couldn't.
The following is the source.
Please advice me.
best regards,
yu-yu
ManagementPath path = new ManagementPath();
ManagementBaseObject inParams = null;
ManagementBaseObject outParams = null;
string[] stemp = PrinterID.Split("\\".ToCharArray(), 8);
path.Server = stemp[2];
path.NamespacePath = @"root\CIMV2";
string relPath = string.Format("Win32_Printer.DeviceID='{0}'",PrinterID);
path.RelativePath = relPath;
try
{
ManagementObject mo = new ManagementObject(path);
outParams = mo.InvokeMethod("SetDefaultPrinter", inParams, null);
Console.WriteLine("Printer {0} is default now ", PrinterID);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
|
|
|
|
|
What didn't work about it? Give us a clue. Was an exception thrown and written out to the console in your catch block? Was the printer found? Make sure you're doing checks to see if an object is null, too. What if your printer object wasn't found. Since your try-catch block doesn't encompas everything, a NullReferenceException would've gone uncaught.
Microsoft MVP, Visual C#
My Articles
|
|
|
|