|
Hi folks,
I have a simple question for ya (At least I hope it is!)... How can my app find out what folder it is in? This might change regularly, so it needs to know lol
Cheers, Ben.
|
|
|
|
|
Hi,
try this
System.AppDomain.CurrentDomain.BaseDirectory()
Or
system.Environment.CurrentDirectory
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Thanks, this worked
Environment.CurrentDirectory
|
|
|
|
|
Do not use Environment.CurrentDirectory. It could potentially change between application launch and accessing of the property. If you're writing a WinForms app, use Application.StartupPath[^] instead. If it's a command line app, use the first property suggested by the other poster AppDomain.CurrentDomain.BaseDirectory[^].
|
|
|
|
|
In addition to what Senthil said:
The Environment.CurrentDirectory property contains the current working directory. The startup working directory can be specified in the properties for an application, so even if you don't change the working directory from your program, there is still no guarantee that the application file is in the current working directory.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I believe I am familiar and know the concept of OOP.
Can you recommend a book on OOP in C# please?
Thanks
|
|
|
|
|
I recommend you Wrox Professional C#.
Saqib
|
|
|
|
|
Try the excellent 'Programming C#' by Jesse Liberty.
Dave
|
|
|
|
|
Try SAMS C# Unleased, if you are a starter on the .NET framework
Oliekrokenosterpikkelikkeastrysvoel
|
|
|
|
|
Hi All,
I use FileSystemWatcher for monitoring some folders. When a new file is created i wait until it is completly written to disk and then i copy that file to another folder. I am using the FileSystemWatcher events OnCreated(), OnChanged, OnError(). Proper handlers are attached to these events. This code worked perfectly until yesterday. Yesterday suddenly the FileSystemWatcher stopped giving events for file creation, change etc. Not even an Error occured. what may be the probable reason ? Is there any dependancy for FileSystemWatcher ? I didnt changed the code which was working. So i think if there is any dependancy it might be external.
I tried to search the net for a possible solution but i only found that there are a lot of people complaining about FileSystemWatcher. So i will also like to know if there is some other class or component available which can just replace FileSystemWatcher ?
Any sort of information or help will be appreciated. Please reply as soon as possible since i have wasted a hell lot of time on this FileSystemWatcher !
Thanks in Advance.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
You're going to have to do some root-cause-analysis to find out the why. For example:
1) if it is a service (you did not say) is it still running?
2) a sudden change in code is triggered by an event. What change day-before-yesterday?
3) did something unexpected happen like a power surge or power outage?
So it is a very basic part of programming to walk through the possible issues until you find out the event that caused your process to fail. Since you remained at a high level of discussion (not providing all details) there can be just so much that can be provided for help.
|
|
|
|
|
hi theRealCondor,
Thanks for the reply and sorry that i was not able express my problem details properly, but now the problem is solved. Actually my problem was that i was using FileSystemWatcher in a windows service and the Watcher stopped triggering events. Though i didnt changed any code related to that watcher. I posted the same query on microsoft's forum and some one told me to check the log on acount for the service. I changed my log on account and the events started to trigger again. By the way, i was talking about FileSystemWatcher events whcih are generated when file is created or change, etc..
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
This is what I'm trying to do:
Target value is 0xffffff9d, which translates to 4294967197 decimal, which is why it needs to be an unsigned int. Unfortunately whenver I attempt to do this, it spawns an overflow exception.
Two lines of code that matter:
RegistryKey TargetKeyNode = Registry.LocalMachine.OpenSubKey(TargetPath, true);
TargetKeyNode.SetValue(TargetKeyName, TargetValue, RegistryValueKind.DWord);
As a brute force method, I've tried creating the target key as a dword with a zero value and then stuffing in the needed value using RegistryValueKind.Unknown, but that simply changes the key type to a string.
I also tried setting the value this way &Hffffff9dI (along with every possible variation of that) as was suggested for someone else on another website but I get an error "The name &Hffffff9dI does not exist in the current context" on build.
Can anyone please help me with this? Thanks in advance for any help.
Mike Poz
|
|
|
|
|
You can cast the uint value to int, without losing data. The int value will be negative, but having the same bit pattern.
---
b { font-weight: normal; }
|
|
|
|
|
Thank you very much, that worked exactly as you said. Never though of the old "wrap around" trick. Thanks again!
Mike Poz
|
|
|
|
|
Hello fellow programmers,
I am one of the poor souls who tried to dynamically load a dll and discover its types, methods of types, etc.
Now, an example in the vs2005 help environment (and also some online articles by c# programmers) shows that one can use the common line compiler csc with the option "/target:library" and call Assembly.LoadFrom("xxx.dll") etc. and there you go! It works.
However, if I create a dll (not really a dll, as I have found out) through a class library or a control library project, it can't be loaded as an assembly (unless it is in the same solution as your calling application).
I am wondering the difference between using the csc and the visual studio environment. Can I do the same trick from within the visual environment? What sort of C# project must I use to create the kind of library that csc creates?
I will be grateful for any comment on the subject and pass it along to any other programmer who may tackle the same issue.
Hurol
|
|
|
|
|
You should use ClassLibrary type project to create dll in VS.
Saqib
|
|
|
|
|
Hi
is there a way i can send or give access\reference to Buffer i have with BMP image inside to another
object application written in C++ unmaneged?
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
<br />
namespace LoadImageBMP<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
<br />
mLoadImagetoBuffer();<br />
pb1.Image = System.Drawing.Image.FromFile(@"M:\Inbox\Card.bmp");<br />
<br />
<br />
}<br />
private void mLoadImagetoBuffer()<br />
{<br />
<br />
Image Mbmp;<br />
Mbmp = System.Drawing.Image.FromFile(@"M:\Inbox\Card.bmp");<br />
<br />
}<br />
}<br />
}<br />
i want to semd give acess to Mbmp.
any idea would help.
Have a nice Day
|
|
|
|
|
I think you must first take a look at how to use managed code in unmanaged world.
http://www.codeproject.com/managedcpp/ijw_unmanaged.asp
|
|
|
|
|
thanks i am reading it now
Have a nice Day
|
|
|
|
|
Hai,
How should I get the IP Address of my clients(in ASP.Net,C#)?
|
|
|
|
|
Hi AnjuV,
You can use the Request object.
Request.UserHostAddress
By the way you should have posted this query in the ASP .NET message board.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
I am new to C#, I create a WinApp with FormMain.cs & userControl.cs. userControl add to left panel of FormMain, and dataGrid1 add to right. When I click on btn_search and I get a run time error "Null Reference Exception was unhandled". How can I pass the search result to right side dataGrid1?
thank you
Ken
in userControl.cs
...
void btn_search_Click(object sender, System.EventArgs e)
{
...
ora_Connect(sql);
}
void ora_Connect(string strSql)
{
// Create and open a new connection
m_connection = new OracleConnection("Host=vmtestxp;Port=1521;SID=xe;User ID=abc;Password=abc");
m_connection.Open();
adapter = new OracleDataAdapter(strSql, m_connection);
cb = new OracleCommandBuilder(adapter);
dataSet = new DataSet("DS");
adapter.Fill(dataSet, "TABLE");
_dataGrid1.SetDataBinding(dataSet,"TABLE");
}
private System.Windows.Forms.DataGrid _dataGrid1;
public DataGrid dataGrid1_Temp
{
get
{
return _dataGrid1;
}
set
{
_dataGrid1 = value;
}
}
....
in FormMain.cs
usercontrol dc = new usercontrol();
void frmMain_Load(object sender, System.EventArgs e)
{
dc.dataGrid1_Temp = this.dataGrid1;
}
-- modified at 10:47 Monday 31st July, 2006
|
|
|
|
|
Hi,
I am programmig an app with a few window forms and users can copy
text from controls(e.g. textBox) from one form to another by highlighting
the text and click the copy menuItem in the mainMenu (not using contextMenu coz there would be no problem by using contextMenu with the control)
The problem is, how can the app know which control the text is copied from when the user clicks the copy menuItem ? Do I need to register a control
highlight or ???? event to each control so the app can know which control is being highlighted with text ? But it seems quite tedious coz there are many textBoxes on each form and may affect the performance coz many event listeners are registerd. Any better solution ?
Thanks
|
|
|
|
|
Hi, I think in the mainMenu click event you can just check the focus control and then if the focus control is a TextBox then you can get the selected text from it to use in copy operation.
Saqib
|
|
|
|