|
thanks for the reply.
continuing the same topic;
How to set any one of Printers as Default Printer?
regards
|
|
|
|
|
The easiest way is through WMI. While on NT-based platforms you can make a single function call (you have to P/Invoke SetDefaultPrinter ), the steps for Windows (i.e., Win98 and ME) platforms are more numerous.
WMI exposes a Win32_Printer.SetDefaultPrinter method that abstracts the correct implementation:
using System;
using System.Management;
class Printers
{
static void Main(string[] args)
{
EnumeratePrinters(args.Length > 0 ? args[0] : null);
}
static void EnumeratePrinters(string defaultName)
{
ManagementObject defaultPrinter = null;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"select * from Win32_Printer");
foreach (ManagementObject printer in searcher.Get())
{
string name = printer["Name"].ToString();
Console.WriteLine("Printer: " + name);
if (defaultName != null &&
string.Compare(name, defaultName, true) == 0)
defaultPrinter = printer;
}
if (defaultPrinter != null)
{
Console.WriteLine("Setting default printer to \"{0}\"",
defaultPrinter["Name"]);
defaultPrinter.InvokeMethod("SetDefaultPrinter", null);
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi~
I am writting a program to get the email using MAPI by P/Invoke.
Except inbox, Can I get the emails item from other folder such as outbox?
Thanks
|
|
|
|
|
hi,
how to preprocess "ctrl + c" in console program,i want to using .net class implement this function.
thanks
|
|
|
|
|
Each time I try to create an ASP.NET Web Application I get the "Web Access Failed" dialog box...IIS is installed and running correctly, however I keep getting the following error message:
<br />
The default Web access mode for this project is set to file share, but the project folder at 'http://localhost/WebApplication1' cannot be opened with the path 'c:\Inetpub\wwwroot\WebApplication1'.
Can anybody explain why i keep getting this? IIS is running correctly and so are the rest of my Visual Studio .NET applications...I only get this when I try to create Web Applications...
Thanks
|
|
|
|
|
This may happen if you are not exceuting your application in Administartor or same privilaged environment. Try to execute your web application in Administrator mode. If it is not serving your purpose try to post in Asp.net thread.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Hi all,
I got this C++ dll that comes with a input/output card, How do I import and start using this in C# . Do point to any useful reference . Thank You
|
|
|
|
|
Consuming unmanaged components and .dlls are very easy in .Net Framework. Please go through Interop and P/Invoke technologies of .NET.
P/Invoke and Interop
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Thank you very much. Very useful link
|
|
|
|
|
Hi,
I want to make my application to support 2 or 3 languages. But how can I make a good and convenient localization kit for my applucation?
I have no idea to make it, could anyone suggest to me or give me some example?
thanks a lot !!!
|
|
|
|
|
|
how can I prevent window1.show() from showing same window multiple times.
Are there any command like..
if (window1 exists)
don't open window1
thanks
Sudeep
======
code proj. rocks!
|
|
|
|
|
You can use a static field to keep track of the window state. When the window opens set the field to true. When the window closes set it to false. Check the field before trying to show another copy.
Another way is to just to use ShowDialog() I don't know if that works for you.
|
|
|
|
|
Hi all,
How can I use c# to manipulate the favourites in Internet Explorer, e.g.
import and export favourites from the IE ?
Thanks
Patrick
|
|
|
|
|
Favourites are just stored as text files in your profile
e.g. C:\Documents and Settings\[your profile]\Favourites\
Open one of the files in notepad and you'll see the format is fairly straightforward, so it should be pretty simple to write code that'd read each file in, parse it, and store it in some kind of tree structure
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
You should never hard code paths when there's better alternatives. In this case, you can use Environment.SpecialFolder.Favorites . See my previous post for details.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Ahh, even better - yeah, I knew favorites are stored in all sorts of places - I was just giving the guy a starting point
(I assume that'll give the right path on Win95 systems that stored favorites in the c:\windows\favorites\folder\ ?)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
The .NET Framework isn't supported on Windows 95, and Windows 95 hasn't even been supported in general by Microsoft for a couple years now.
On supported platforms (at least on Windows), however, the correct path is returned.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
d'oh - of course not!
Will .NET 2 support the same platforms that .NET 1.x did? (The stuff I've read has been pretty ambiguous)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
|
The easiest way - since Internet Explorer favorites are nothing more than .url link files - is to move, copy, or delete files from the Favorites directory, which you can easily get using:
string favorites = Environment.GetFolderPath(
Environment.SpecialFolder.Favorites); From there you can use various classes in the System.IO namespace - such as the File and Directory classes - to manipulate the file system.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I am trying to understand the following probem I am having with C# code trying to access a COM object which is generic.
Actually it can be recreated as follows:
Create a VB6 COM dll with a method as follows:
Public Function TestCSharp(ByVal sObjectName As String) As Object
If sObjectName <> "" Then
Set TestCSharp = CreateObject(sObjectName)
End If
End Function
Now write a C# class to access it and write the following code
CSharpTest.InterOpObjClass oObject = new CSharpTest.InterOpObjClass();
ADODB.Recordset oRS;
oRS = (ADODB.RecordsetClass) oObject.TestCSharp("ADODB.Recordset");
It gives an error saying specified cast is not valid, basically an invalid cast exception
Now try the same in VB.net
Dim oObject As CSharpTest.InterOpObjClass = New CSharpTest.InterOpObjClass
Dim oRS As ADODB.Recordset
oRS = oObject.TestCSharp("ADODB.Recordset")
This works fine.
Why is C# unable to unbox the value? I have noticed this for all interop objects that return type Object.
C# seems to treat them as System.__ComObject and I guess it does not like a conversion between System.__ComObject and ADODB.RecordSet or infact any other.
Is there a way around this in C#?
|
|
|
|
|
|
I already have seached google hehehe and find many search results, experts please help.
I want to test my knowledge on the C# language, is there a free site where I can take a practice test. I already tried cert21, but the free test questions are very few.
Sorry for my bad english.
Thanks in advance
|
|
|
|
|
Well, the obvious approach would be to read this forum, and answer as many questions as you can. I'm sure there are other, similar forums, probably a whole hive of them in the microsoft newsgroups.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|