|
I was wondering if there was a way to get the name/id of a process that is locking a file.
When I run try to open a FileStream and get the annoying "The process cannot access the file 'somefile' because it is being used by another process." message, can I get witch process is using that file or is that out of reach in C#?
|
|
|
|
|
I don't know how to do it in c# but here is c++ way: Deleting Locked Files[^]
You can use P/Invoke and use it in a .NET application
|
|
|
|
|
How to automatically Highlight (Select) value of a Textbox ,when typing the value in Textbox.
|
|
|
|
|
Look at the Select and SelectAll methods as well as the SelectedText, SelectionLength and SelectionStart properties of the TextBox.
|
|
|
|
|
I need two way communication between a Windows Service and my Windows Forms Application that will be running on many computers across a LAN.
The service will need to accept small but frequent ammounts of data from all the winforms apps simultaneously and to be able to send response messages back.
Would named pipes be the best solution?
|
|
|
|
|
I'm looking for some organizational tips on the best approach to organize our company's c# excel reports and was curious how some of you handled this task.
Currently, we create dozens of reports via c# console applications using the "microsoft office 11.0 object library". We then simply schedule them to run at a certain time (daily, weekly, monthly).
Yesterday, we had a meeting however, and realized we now have dozens of these report projects all over the place, spread out among 5 different developers and nobody really knows who's working on which reports. So we've decided to look into creating a single, clean solution to handle ALL reports.
So I'm just looking for some ideas as to the best approach to take with this in order to keep everything organized AND where any developer could jump into another developers report project in their absense.
Thanks.
-Goalie35
|
|
|
|
|
|
This is probably something easy for someone who is experienced with Regex and regular expressions in general. Unfortunately, I am not one of those people. Perhaps one of you kind souls will take pity on me and help me out here.
I need to replace a part of a string with another string. I only want to replace the first instance. An example of the the beginning of the string being searched is as follows:
<chart first_node_id="None" item_id="323f359f-f2db-4cd5-b779-aebc1349d587" form_type="None" name="here is an old name" last_modified="1/16/2008 11:03:33 AM"><br />
<node name="don't change this name" node_id="ff918de6-213d-4a11-8c1c-ce5b54c7d8f2" result="None"
What I want to find and replace is the "here is an old name" part. Note that 'name=' is repeated, and I only want the first one replaced.
I've tried several different expressions, but the one I am currently toying with is as follows:
<br />
Regex regExp = new Regex("name=\"(.*)\"");<br />
string test = regExp.Replace(oldString,newName,1);<br />
This doesn't do what I want. It finds 'name="here is an old name" last_modified="1/16/2008 11:03:33 AM"' and replaces the whole thing instead of just what is between the quotation marks.
I've been trying to read up on reg expressions and Regex, but the time crunch I am under is making me impatient and it is hard to learn with that mentality. So, any help you can provide would be most appreciated. Thanks in advance.
|
|
|
|
|
You need to use a "non-greedy" or lazy flag on the .* part. So it would be .*?
It is documented here[^].
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I thought I had tried the lazy flag, but it seems to have fixed my issue. Thanks!
|
|
|
|
|
Another tip for you - download Expresso[^] if you haven't already as it makes working with RegEx's much simpler.
|
|
|
|
|
Hi all,
Is there a C# way for retrieving the number of currently opened sql-connections?
Thanks in advance,
Danny
|
|
|
|
|
DannyAdler wrote: Is there a C# way for retrieving the number of currently opened sql-connections?
Yes. The SQL query to return the connections is:
select * from sys.dm_exec_connections
I suggest you create a stored procedure in your database, and call that SP from your C# app.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
Thanks for the reply man.
Here's the query result:
Invalid object name 'sys.dm_exec_connections'.
Using SQL Server 2000...
Any idea?
Danny
|
|
|
|
|
Works fine for me. I ran it from code, and I just opened up a SQL Query in SQL Server Management Studio Express and ran it. Would you post the code you are using to execute the query? I'm looking to see if that exists in SQL 2000.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
No code...
Just by running your query on the Enterprise Manager and on the Query Analizer apps.
Maybe it's a version thing.
Danny
|
|
|
|
|
Found it on this dude's blog:
http://sqljunkies.com/WebLog/sqldude/archive/2004/06/14/3146.aspx[^]
Quoting:
Now to obtain the current number of connections to the server, you can use:
SELECT COUNT(*) AS CONNECTIONS FROM master..sysprocesses
And just to get the user connections, omitting the system processes, use:
SELECT cntr_value AS User_Connections FROM master..sysperfinfo as p
WHERE p.object_name = 'SQLServer:General Statistics' And p.counter_name = 'User Connections'
Thanks anyway.
Danny
|
|
|
|
|
Hello All,
Has anyone come across any code that will convert a set of tiff files to an avi?
Thanks.....
|
|
|
|
|
Hi all,
So I have a Bitmap field, now I want to save it to disk, BUT if it has
some transparent pixels, I want to save it as a gif, else save as
jpg.
Sounds reasonable?
How can I do that?
Thanks in advance,
Danny
|
|
|
|
|
There is no such thing a transparent pixels in a bitmap. There's only transparency support in file formats, and in code that sets bitmasks.
The png file format has transparency built in, but when you load a bitmap object it doesn't have support for transparency, it's just not part of the format.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Okay, so maybe my approach is wrong..
Situation:
The user opened an image file, and I load it to a Bitmap, but I don't know if the image has some transparent regions.
Now, regardless to the original user's image file's format, I want to save the image to disk, Image.Save (String, ImageFormat).
So if the original image had some transparent regions, I would want to use an ImageFormat that has support for transparency (png/gif), and if there were no transparent regions, I would use Jpeg.
Questions:
Does this requirement make sense?
How can I handle this kind of situation?
Thanks,
Danny
|
|
|
|
|
Hello,
I have a userControl that has a string property. I want that, instead of typing in this property, the user gets a comboBox with strings got from a database.
I've created a new class that has a GetStandardValues method, like this:
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
ArrayList permissions = new ArrayList();
permissions.Add("test1");
permissions.Add("test2");
permissions.Add("test3");
return new StandardValuesCollection(permissions);
}
When I set the typeConverter of the property at my userControl to be the type of the above class, it works. The control's property diplays the test strings in a comboBox.
But when I try to bring this strings from a dataBase, it doesn't work.
I've already tried this:
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
ArrayList permissions = DataBase.GetPermissions();
return new StandardValuesCollection(permissions);
}
Anybody has can help me?
Thanks
Peterson
|
|
|
|
|
Peterson Luiz wrote: When I set the typeConverter of the property at my userControl to be the type of the above class, it works. The control's property diplays the test strings in a comboBox.
But when I try to bring this strings from a dataBase, it doesn't work.
What do you mean "it doesn't work?" Does it throw an error, does it return nothing? When posting a question be as descriptive as possible.
Peterson Luiz wrote: I've already tried this:
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
ArrayList permissions = DataBase.GetPermissions();
return new StandardValuesCollection(permissions);
}
Anybody has can help me?
Have you tried setting a breakpoint on the return to see what the values in your permissions ArrayList ? If it doesn't throw an error, maybe you aren't returning anything from your database.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
Hello,
When I said it doesn't work, I get an NullReferenceException. But, if I put the same code somewhere else and try it in runtime, it works perfectly. It returns all the strings I want from the database. So, the code is right, but doesn't work in design mode, with the usercontrol.
I get the NullReferenceException at the line
ArrayList permissions = DataBase.GetPermissions();
Thanks
Peterson
|
|
|
|
|
Peterson Luiz,
I think you just answered your own question. By the sounds of it, you're trying to view information in design mode when you don't have a database connection.
Either, put the below at the top of your method to stop the method accessing the database:
If (DesignMode)<br />
return;
OR. When ever you call the object DataBase, check if its null and create a new instance.
Regards,
Gareth.
|
|
|
|