|
There's two things you must keep in mind - the application directory and the current working directory. When you start an application, the current working directory may not necessarily be the same as the application directory. Double clicking the EXE would yield this result, but a shortcut to your application may define a different working directory. A working directory can also be changed at runtime (i.e., while your application is running).
If you want that file to always be relative to your application, use the Application.StartupPath like so:
string filename = Path.Combine(Application.StartupPath, "file.dat"); Without specifying a full path starting from the drive path, the current working directory is used to resolve the file path.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a service that I built which sends emails out to subscribers which I have been testing for the past two weeks. I want to launch it into release mode running on my computer as a service, but I also want to be notified when the 'job' starts so I can monitor the logs.
I thought that I might like to have my computer beep a half dozen times when the job starts so that I will be notified.
However, it is a service therefore no window and no reference to windows.forms. I search through MSDN and codeproject and found many references to using DirectX and using MessageBeep but I don't really want to increase the size of my project to have references to large namespaces which will not really be used.
Is there another way to access the pc speaker and emit a tone via a service? If not, any other ideas how I could notify myself when a service starts processing work?
Tim
|
|
|
|
|
I have no idea if this actually works still in c#, or if you can do it in a service...but when I used to use C/C++, I would output \a to produce a generic system beep. In C++ it looked like this:
cout << "\a";
You might want to look at that as an option...
Good luck
- DougW48
dwright@tdci.com
|
|
|
|
|
That brought me back to Borland Turbo C and printf("\a")!
I tried Console.Write("\A") which I believe is the C# equivalent and unfortunately it didn't work...
Tim
|
|
|
|
|
Won't work since you don't have a desktop, UI, CONSOLE WINDOW to output anything to. So, no beep...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You can call the native implementation, you just need to P/Invoking the signature. The following will allow you to call MessageBeep .
[DllImport("user32.dll")]
static extern bool MessageBeep(uint uType);
|
|
|
|
|
A service can actually interact with the desktop because it can create a window station either one of two ways.- Run the service as SYSTEM and check the interactive option. This is highly discouraged, however, because a service rarely needs SYSTEM (like Administrative) privileges.
- Run the service as a user with interactive login rights. That user can still login interactively, but the service runs as that user. A separate window station (which hosts a desktop) is created for both.
You can read more about Windows Services - in general - at http://msdn.microsoft.com/library/en-us/dllproc/base/services.asp[^].
I am planning on releasing a new article about this hopefully this weekend if I get time to finish it up, so keep an eye on my articles if you'd like.
You could simply P/Invoke the native Beep API:
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool Beep(
[MarshalAs(UnmanagedType.U4)] int dwFreq,
[MarshalAs(UnmanagedType.U4)] int dwDuration);
public void Beep()
{
if (!Beep(256, 500))
throw new Win32Exception();
} This is by far more simple.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Damn! :-> Beat me to it!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
I'm trying to find a way to determine the size of the text in a LinkLabel. I want it to automatically resize itself. Other controls have a ContentsResized event, but the LinkLabel is sadly lacking. Any ideas? I was thinking that I could create a Graphics object from the control and call MeasureString to get the size of its text - when would be the best time to do this?
Will
|
|
|
|
|
Handle it in the TextChanged event. You are on the right track with using the MeasureString graphics object.
Good luck
- DougW48
dwright@tdci.com
|
|
|
|
|
That does make sense now that I've woken up a bit.
Thanks,
Will
|
|
|
|
|
Hi all,
been looking for a solution the following:
I have images of some buildings. The images are in perspective, and i would like to transform them so that it is in orthomode: top width is same as bottom width
Building on the initial photo image [perspective]:
/--\
/ \
/ \
/---- ---\
Building transformed to correct proportions:
----------
| |
| |
| |
----------
I've seen some people talk about Ransac but that needs 2 images from the same target so it can rectify based upon edge points.
I know the size of the building in meters. The corners are measured. Also i know the positions of the corners of the windows and doors.
Those points are 'picked' on the 'perspective image' also and the wish is to transform the perspective using the transformation parameters from the source- and target points into a new image.
Does anyone have an example, prefereably C#, or the theory behind this so i can reproduce the action?
Gdi 'only' has the option to rotate/move/skew but not something like the rectify i am looking for.
Hope someone can send me to the correct grid here )
Jan.
PS. the procedure is a little like creating a panorama --> identical points on the images should result in a combined image.
In my case i need the one image to be transformed to the coordinate system of the points of the measured building.
|
|
|
|
|
|
I want to know what are the classes that enable me
to controle by resource in C# like printer,flopy,cd room ,scanner,...
thanks.
|
|
|
|
|
Your english does not make sense.
If you're asking what classes to use to control the cd rom, floppy, printer, scanner, there's a wide variety of possibilities: for file and folder browsing, look at the System.IO namespace. For printing, look at System.Drawing.Printing.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
Hi,
I want to know how to make the group headings appear in larger or bold type font.
Anyone know how to do this ?
|
|
|
|
|
And what "group headings" would those be? You need to be specific if you expect any sort of decent help.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The "group names" then ? When you form the list into groups I want the group names to appear in bold or larger font.
"group name"
-------------------------
Group Item 1
Group Item 2
|
|
|
|
|
The ListView in .NET 2.0 will support this, but for now you should read the documentation[^] for List-View controls - the Windows Common Control that the ListView class encapsulates. You can also only do this on Windows XP because it requires you to bind to the Common Controls 6 library, which is a Win32 side-by-side (SxS) assembly only for XP and above.
To bind to CC6 in .NET 1.0, read my article[^]. For .NET 1.1, you can do the following for your entry point method:
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
} You then need to P/Invoke SendMessage and declare several structs, like the LVGROUP struct and LVITEM - as if _WIN32_IE were set to 0x560 or above (read the documentation I linked and you'll see what I mean) - in order to 1) define groups, and 2) put ListViewItem s in a particular group. There's a lot to do, and knowledge about native Windows programming with the Common Controls is practically required.
For a decent article and sample code, see the article C# ListView 1.3[^] (a.k.a. "Glacial ListView").
For information on what's in the Whidbey (.NET 2.0) beta regarding this issue, see http://msdn2.microsoft.com/library/System.Windows.Forms.ListViewItem.Group[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I believe you're going to have to P/Invoke in order for it to work. The ListView doesn't expose any way to deal with it.
--
Joel Lucsy
|
|
|
|
|
I want to know what are the classes that enable me
to controle by resource in C# like printer,flopy,cd room ,scanner,...
thanks.
|
|
|
|
|
You're going to have to be a little more specific than that. If by "controle" (actually, "control") you mean to print to a printer, then read the documentation[^] for the System.Drawing.Printing namespace classes. There's lots of examples in there was well.
To access a floppy you use one of the System.IO classes - like the FileStream - to open a file on, for example, your "A:\" drive just like you would any other file (that's what an operating system is supposed to provide - transparency). Same goes for a CD-ROM.
For a scanner you'll need to search[^] for something like "C# twain driver". There may be some articles on this site as well, but you'll again have to search using the text box at the top of every page underneath the logo. Research is part of development.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi everyone,
I am using a view in SQL server as a filter in order to show only a subset of rows to the user (depending on specific rights noted in a separate table).
At the same time I make use of the SqlCommandBuilder because I do not need any specific control over the sql statements.
This works nicely as long as select rights are granted to the user to both the view AND the underlying table. If I switch off the select right on the table (which is why I am doing this in the first place) the CommandBuilder cant find the schema information necessary to build the commands.
Now: The necessary schema information is present in the program in the form of a dataset containing all the tables, PKs and FKs (it gets the information at design time, no need to access the DB at runtime).
Does anyone have an idea how I can convince the SqlDataAdapter or the SqlCommandBuilder to make use of this information rather than to retrieve it from the server?
Anything that would save me writing tons of dumb sql-statements would be greatly appreciated!
hajo
|
|
|
|
|
SELECT privileges are still required on the table. A view is just a view on that table.
If you look at the documentation for the SqlCommandBuilder - or better yet look at the IL using ildasm.exe for the System.Data.dll assembly - you'll see that it only gets its schema information from the database. To do otherwise could pose a problem. While you may give correct schema information using a DataSet schema, someone else may not.
If the SqlCommandBuilder doesn't suit your needs, implement the other SqlCommand instances for the SqlDataAdapter yourself. It's not difficult.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
SELECT privileges are still required on the table. A view is just a view on that table.
In the general case, this is not true; shielding the underlying table from direct user interaction is one reason that views exist.
In the specific case of a commandbuilder, it might be true due to the way the commandbuilder queries metadata about the underlying table.
|
|
|
|