|
The following have either returned null or returned the Windows\System32 directory:
System.Windows.Forms.Application.ExecutablePath;
System.Reflection.GetExecutingAssembly();
System.Reflection.GetExecutingAssembly().CodePath;
Environment.CurrentDirectory;
Does anyone know anything that actually works?
|
|
|
|
|
I used AppDomain.CurrentDomain.BaseDirectory
|
|
|
|
|
System.Windows.Forms.Application.ExecutablePath; works for me.
Two other methods that may work:
System.Reflection.Assembly.GetCallingAssembly().Location <br />
System.Reflection.Assembly.GetExecutingAssembly().Location
|
|
|
|
|
Does it work for you when running a service??? Running a service is a unique situation because of how it is started and the context that it runs. I also listed all the ways that I succeed in getting null which includes your "other two methods".
|
|
|
|
|
Yes, I write services too, and I tested these within a service.
Actually two different services.
One is simple, with all the code in one executable.
The other is much more complex, with pieces in various DLLs, the actual service code is in a DLL that gets loaded dynamically through System.Reflection.Assembly.LoadFrom .
I don't know how much more complex yours could be.
|
|
|
|
|
Hi,
I wanted to catch two different types of exceptions in custom log file code. When the second instance of log file is trying to write while the first instance is still writing some message, C# is throwing IOException when the file is opened in Append and Share None mode.
When I try to access a folder which does not exists, in that case also compiler is throwing the same exception.
I tried with the following code:
try
{
FileStream fileWriter = File.Open(@"C:\Test\Test.log", FileMode.Append, FileAccess.Write, FileShare.None);
FileStream fileWriter1 = File.Open(@"C:\Test\Test.log", FileMode.Append, FileAccess.Write, FileShare.None);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Is there any way to catch those two scenarios with some unique identity?
Please advise in email to rajesh_a_kumar@dell.com
Thanks,
Rajesh
rajesh_a_kumar@dell.com
|
|
|
|
|
rajesh_kumar_24 wrote: When I try to access a folder which does not exists, in that case also compiler is throwing the same exception.
Why not check if the folder exists [System.IO.Directory.Exists(strPath);] rather than throwing an exception. If the folder doesn't exist, you can write to a log file to log the error.
rajesh_kumar_24 wrote: When the second instance of log file is trying to write while the first instance is still writing some message, C# is throwing IOException when the file is opened in Append and Share None mode.
Why not write a function to pass the string to be logged and the function will look after reading and writing to the file. Is there a reason you want to open 2 different filestreams?
|
|
|
|
|
Actually, I have 5 different components trying to use the log class. All 5 instances can try to write the message to log file at the same time. So, I want to keep rest of the 4 in waiting (loop) till 5th one completes its logging. I can control this loop and with the help of a static variable.
Can you please advise how to achieve this?
|
|
|
|
|
You should put a separate class for logging. The class will look after writing to the log file, every component/class in your code can create an instance of this class and log the details to it. I am actually writing an article on this and should be out in 2-3 days time. You can have a look at this article by Ravi Bhavnani[^]
|
|
|
|
|
Catch DirectoryNotFoundException and IOException.
---
single minded; short sighted; long gone;
|
|
|
|
|
Try:
catching (IOException ioex)
{
// Then do what Microsoft says as below for the IOException message class:
//The constructor initializes the Message property of the new instance to a system-supplied
// message that describes the error, such as "An I/O error occurred while performing the
// requested operation." This message takes into account the current system culture.
}
|
|
|
|
|
Does anyone know of a good tutorial for setting up a website for HIPAA compliance?
I'm developing a simple c# website for a friend who owns a small company based in the medical field. Now that his company is growing, he wants to allow his doctors to log into his website to view their patients' test results rather than having to snail mail out the test results every day.
This brings us to a rather delicate issue because even though it's just a few simple pages on the website to view this test result data, I think we're now into HIPAA compliance territory. Meaning we'll have to look at more secure (and expensive) measures than what is currently being performed. For example, I was looking at a web hosting service that provides .net hosting & shared sql server for $15/month. Will I now need to look into a $199/month dedicated server (which probably would cancel the project since, as I said, it's just a simple website with a few small simple features).
Thanks for any help on this.
-Goalie35
|
|
|
|
|
Goalie35 wrote: Will I now need to look into a $199/month dedicated server (which probably would cancel the project since, as I said, it's just a simple website with a few small simple features).
Yes, this will most like cancel the project. You're now getting into patient privacy and security issues that will make this "little" website prohibitively expensive to run. You may want to talk to an actual HIPPA consultant/lawyer, instead of a developer, to cover the legal issues of patient data privacy and what your requirements for compliance are.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Dave is spot on - HIPPA is no joke. If you don't have a few lawyers and compliance consultants looking over your stuff, you're asking for serious federal trouble.
It's not just protection of data in transit either - it's on-disk protection, display protection, portable-media protection, and view/modify/delete audit trails for all protected info. Giant insurance companies are spending millions just figuring out what they've got to do to be compliant - and they've got to follow the same rules your web site does.
"I hope he can see this, because I'm doing it as hard as I can" - Ignignot
|
|
|
|
|
Are there any 'patterns' for using a CheckBox group for a bit field? At the moment I'm setting the Tag property of each CheckBox control to a key into a Dictionary that contains an object represented by the checkbox, but I would like to achieve a generic means of dealing with these scenarios.
|
|
|
|
|
Hi,
How to embed a .exe file in c# windows application
Thanks,
|
|
|
|
|
Define "embed"?
In the most direct sense, no, you can't "embed" the .EXE in your app's resources and expect to run it directly from the resources. You'll have to copy the .EXE from the resources to a file on the hard drive, then run the .EXE from the file. The file will exist, and be locked, for the entire time that .EXE is running.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
If that exe file is a .NET application you can load it in memory and run it
|
|
|
|
|
You can, but that's a big IF. Usually, when someone asks this question, it's because they want to add an .EXE that they don't have control over, like a command line utility or some other small Windows app.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I mean to use the .exe as a part of my windows applic, as when u embed .swf file in your applic interface, but here i need to meke the user use the .exe only as a part of my window, not as a separate window of it self..
Thanks for your reply..
|
|
|
|
|
It's possible, but not recommended as it can cause visual problems for the hosted app and is not what I would call a "production quality" solution. If this "embeded" app is a .NET-based .EXE, then you can run it out of the resources of your app. If not, then you must run it from an .EXE file on the hard drive.
After it starts and puts up it's main form, you can call the Win32 API functions FindWindow and SetParent to set that window's parent to a window, like a Panel, in your application.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
the .exe is a macromedia flash .exe file, i tried to use the shockwave but it only runs .swf, i don't know if this makes a difference in the solution, and i hope if you could explain me more about finding the window and setting its parent if this is the only solution.
Thanks again..;)
|
|
|
|
|
Somehow, I just knew there was no good reason behind this...
If you launch the .EXE using the Process class, you can easily get the window handle of the .EXE. Keep in mind, I have no idea if this is going to work for your ShockWave EXE! This code assumes there is a Panel control on your form called myPanel .
[DllImport("user32.dll"), EntryPoint = "SetParent", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndParent);
...
Process p = Process.Start("MyShockwave.EXE");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, myPanel.Handle);
...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
1) Create a new project, File.ReadAllBytes and then write them to a separate file ( .txt, .dat )
2) Add this file to your resources.
3) Load it from the resource at runtime and save to a new file
4) Change extension to .exe
OR
1) Change extension from .exe to .dat
2) Add as a resource
3) Load it from the resource at runtime and save to a new file
4) Change extension to .exe
?) What am I explaining at the moment? Are you trying to write a new kind of virus or just trying to make innocent programmers like me crazy?
-- modified at 12:24 Monday 7th May, 2007
|
|
|
|
|
Actually, his version of "embedding" was hosting the window of another .EXE in a form of his application.
|
|
|
|