|
If you need code, then it's lucky you know how to program isn't it? If not I can send you my consultancy fees - an "urgent" job on a Sunday oh boy oh boy this is going to cost you. Do you have a house you can sell, I'm not quite sure selling the car will do it?
1) Look at System.IO.File.Exists (static method), or alternative System.IO.FileInfo.Exists (member method on the FileInfo class)
2) Opening it is not clear enough. Do you want it to open with the standard registered program (so if it is a .doc file start Word) or display the data in your own program.
If you want to open with the registered program, look at System.Diagnostics.Process.Start (you can give it a path to the file and it will resolve the correct executable for you). If you need to display it yourself use the System.IO namespace to read file (FileStream/StreamReader/BinaryReader are classes you need to know), then build whatever GUI required on top of the data using whatever you require and are familier with: WinForm, ASP.NET, or WPF.
|
|
|
|
|
Check File class under IO .
"Well dude, There's Always Better Ways To Do Things.
BY
BAIJUMAX
|
|
|
|
|
ramyanaidu wrote: its very urgent
That is a very rude thing to say around here.
Your post is a simple one that a quick google search can do for you.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
foreach (myobject value in copy){
...
copy.RemoveAt(copy.IndexOf(value));
...
}
The first iteration works okay, but when the loop starts again, it throws and InvalidOperationException.
Any thoughts as to how I can remove an element within the arraylist whilst still using the same list?
|
|
|
|
|
Hi,
I see two ways to get rid of it:
1.
use a second ArrayList:
1a. if only a few to remove, store the indices to be removed in another empty ArrayList,
then in a second loop, remove those (warning: indices change while removing, so best
do the second loop backwards)
1b. if most of them to be removed, start a new ArrayList and copy the items you want to
keep, then throw away the original ArrayList
OR
2.
don't use foreach, instead use a for loop that runs backwards (or compensate for the
indices changing when removing).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
humblepgmr wrote: foreach (myobject value in copy){
...
copy.RemoveAt(copy.IndexOf(value));
...
}
Hi there,
There was some information at Microsoft about this. You might consider checking out http://support.microsoft.com/kb/555972 to read about it. Looks like a workaround involves creating a copy of the collection within the foreach loop.
Good Luck!
You can't teach people to be lazy - either they have it, or they don't.
-Dagwood Bumbstead
|
|
|
|
|
humblepgmr wrote: aList.sort(); //this doesn't work
Obviously. The Sort method doesn't have any clue how to compare and sort your objects. So, you have to provide an IComparer[^] implementation to compare two of your objects and return the result of the compare.
|
|
|
|
|
Talking to yourself again?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I know. Workin' for the government is drives you to drink. You end up in a dark corner babbling to yourself like an idiot. It'll pass in a few short weeks.
|
|
|
|
|
I have an class defined as below. This class has an integer value assigned to it named initiative. For the purposes of this post this value can be from 1 to 3.
<br />
public class Unit : IComparable<br />
{<br />
....<br />
public int Initiative = ....;<br />
<br />
public int CompareTo(object obj)<br />
{<br />
if (obj is Unit)<br />
{<br />
Unit u = (Unit)obj;<br />
return Initiative.CompareTo(u.Initiative);<br />
}<br />
throw new ArgumentException("object is not a Unit"); <br />
}<br />
}<br />
I have 10 of these objects defined in an array. I want to be able to sort the array by this initiative value however everytime I run a sort I want the object with equal value to be randomly organised. For example if I run sort once:
object - initiative
A - 1
B - 1
C - 1
D - 2
E - 2
F - 2
G - 3
H - 3
I - 3
J - 3
If I run it again, I may get:
object - initiative
B - 1
A - 1
C - 1
F - 2
D - 2
E - 2
G - 3
J - 3
H - 3
I - 3
How can I achieve this using IComparable?
Thanks in advance.
|
|
|
|
|
if (obj is Unit)
{
Unit u = (Unit)obj;
if (obj == this) return Random.Next(2) - 1;
return Initiative
someting like that
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: (obj == this)
This would compare references. Override == operator or write: (obj.Initiative == this.Initiative) .
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Sure - I was really just trying to show how to introduce some randomness. But thanks for adding this, it does make the overall answer more correct.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
PLZ I Want to used xml file as database(how to add,update,delete and Search)
i will make the database program
using interface C# and DataBase <xml>
thanks.
|
|
|
|
|
You can want all you want. It's not going to change the fact that XML is NOT a database. You cannot use SQL statements to navigate through the tables. You have to use the various XML methods to modify your tables, but XML is very inefficient at it.
|
|
|
|
|
Dave Kreskowiak wrote: You can't want all you want.
I don't think that is what you meant... :P
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Whoops. I knew that didn't look right when I posted it...
|
|
|
|
|
Unless your data set is very small, this smells of disaster. XPath is how you search XML. The DOM via the XMLDocument class is how you interact up add/update/delete/search.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
If You really want you can.Once again Is that you really want to do.
check DataSet members ReadXML()/WriteXML()
load XML Store to Dataset using ReadXML ( on Application Initialization )
Manipulate ( add/delete etc.. ) this DataSet during application life cycle.
On ApplicationExit use WriteXML.
"Sometimes solutions will be as simple as 1=1 , confused right "
By
BAIJUMAX
|
|
|
|
|
how to deploy a project which expires after one month.means how to make a demo application
how to give company name ,version when deployinga project.
monu_khan in trouble
|
|
|
|
|
You can't do that via your deployment, you have to create a demo version. And, you need to ask yourself who your market is. A simple way is just to store the install date somewhere, and check if 30 days have passed. People can get by this by setting their clock back, or just by decompiling your app and removing the check. If your clients are likely to do that, then it's a whole lot harder, but a basic 30 day check is trivial to do.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Do not use the word 'urgent' in your post, it is considered rude. It only will anger most people. Most members on this site come here on their own free-will and are not obligated to replying with rude requests like 'urgent'
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Well said.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Needed to get somewhat verbose instead of the typical Don't say urgent style of posts.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Hello,
I have a class without a namespace. The main reason why I don't have a namespace in that class is because I use that class in all my applications.
Now I like to update application settings in that class, but I don't like to use the following line in that class:
using ApplicationNamespace.Properties;
Is there a way where i can reference that up to my class?
|
|
|
|