|
er...
thanks for answering!
what I was trying to do in a simple manner (if possible) is to have one library to run them all!
like imagine my program is a click once application, I would like (if possible) to avoid the x32 link, the x64 link, the CE link.
Just one link and it runs whatever the end-user machine.
Or also imagine the user "install" (i.e. copy) the file on one PC, and then he simply copy on an other PC and it sill works!
Conditional compilation is a clean way to have a build for a given platform.
But I wonder if there is a no hassel way to have one build for all platform that the user could simply copy without worrying about his pc's architecture....
you see what I mean?
is it possible? (in a simple way)
Note:
I did something like that on the PocketPC a while ago but it was akward.
Basically it was worked like that:
enum Platform
{
CE,
Win32,
}
public class OSUtil
{
internal static Platform Platform { get {} }
public Value AMethod()
{
switch(Platform)
{
case CE:
return OSUtilCE.AMethod();
case CE:
return OSUtilWin32.AMethod();
}
}
}
class OSUtilCE
{
static Value AMethod() {}
}
class OSUtil32
{
static Value AMethod() {}
}
|
|
|
|
|
No!
It didn't work like that, too simple!
Don't forget runtim verification when the method is launched, it worked like that:
enum Platform
{
CE,
Win32,
}
public class OSUtil
{
internal static Platform Platform { get {} }
public Value AMethod()
{
switch(Platform)
{
case CE:
return OSUtilCE.AMethod();
case CE:
return OSUtilWin32.AMethod();
}
}
}
class OSUtilCE
{
[DllImport("CEDll")]
static Value AMethodImpl();
static Value AMethod() { return AMEthodImpl(); }
}
class OSUtil32
{
[DllImport("Win32Dll")]
static Value AMethodImpl();
static Value AMethod() { return AMEthodImpl(); }
}
|
|
|
|
|
I know, I could do as I did, but generate the wrapper code automatically
|
|
|
|
|
Hi All,
I currently have an xslt called from C#, this xslt calls(defines an xslt) that uses some jscript functions.
The jscript functions declares a new (microsoft.xmldom) object, this used to worked before when I had just installed msxml 4.0 sp2 in my server, after I installed sql 2005 which installed msxml6.0. this sentence takes too long to execute, sometimes it timeouts. I've commented this line an the xslt executes pretty fast, does anyone has a clue on what might be happening, this seems to happens only when the xslt is being called from C# code, I have several instances of microsoft.xmldom declaration running without any problems,
Any commments will be appreciated.
Thanks in advance.
|
|
|
|
|
Hi All
I have a question relating to the resources/namespaces required when automating either to Excel or Word as I find that namespaces and resources that work perfectly on my machine with Office 2003, do not work with other machines who have Office 2003.
I'm having to type the full Microsoft.Office.Interop.Word/Excel namespace out which in the tutorials and other sample code I've seen, is not the case so I wonder if there is something wrong with my installation.
Here is a little program I created which takes all Word Documents within a directory and merges them into one large Word Document.
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 />
using System.IO;<br />
using Microsoft.Office;<br />
<br />
object oMissing = System.Reflection.Missing.Value;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
lblSelect.Visible = false;<br />
<br />
}<br />
<br />
<br />
private void btnOK_Click(object sender, EventArgs e)<br />
{<br />
Microsoft.Office.Interop.Word._Document oDoc;<br />
Microsoft.Office.Interop.Word._Document cDoc;<br />
Microsoft.Office.Interop.Word.Application wordAppA = new Microsoft.Office.Interop.Word.Application();<br />
Microsoft.Office.Interop.Word.Application wordAppB = new Microsoft.Office.Interop.Word.Application();<br />
oDoc = wordAppA.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);<br />
<br />
folderBrowserDialog1.ShowDialog();<br />
DirectoryInfo di = new DirectoryInfo(folderBrowserDialog1.SelectedPath.ToString());<br />
FileInfo[] diFiles = di.GetFiles("*.doc");<br />
<br />
lblSelect.Text = "Folder currently selected: " + folderBrowserDialog1.SelectedPath.ToString();<br />
lblSelect.Visible = true;<br />
<br />
int count = 0;<br />
foreach(FileInfo fi in diFiles)<br />
{<br />
count++;<br />
}<br />
<br />
progressBar1.Maximum = count;<br />
<br />
count = 0;<br />
foreach (FileInfo fi in diFiles)<br />
{<br />
object file = fi.FullName;<br />
cDoc = wordAppB.Documents.Open(ref file, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);<br />
cDoc.Select();<br />
wordAppB.Selection.Copy();<br />
oDoc.Application.Selection.Paste();<br />
oDoc.Application.Selection.InsertBreak(ref oMissing);<br />
cDoc.Close(ref oMissing, ref oMissing, ref oMissing);<br />
count++;<br />
progressBar1.Value = count;<br />
}<br />
wordAppB.Quit(ref oMissing, ref oMissing, ref oMissing);<br />
wordAppA.Visible = true;<br />
Form1.ActiveForm.Close();<br />
}<br />
Now this works absolutely perfectly on my machine without any fail what so ever but when I try to put it on any other machine even though we both have Office 2003, I get this following error
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Office.Interop.Word, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
I can get around this by having it copy the Microsoft.Office.Interop.Word.dll into the source directory of my application and it will then work but this is a pain because I shouldn't need to do it.
Anyone got any ideas?
Thanks so much
David Bloch
Houston Medical
-- modified at 21:19 Monday 19th June, 2006
|
|
|
|
|
I'm working on a windows application, in the main form I have a few custom controls, which are contained on a different project. In the main form a few user settings are set, and I need the controls to get those settings, but I can't get them. Is there a way that I can share user settings on different projects that belongs to the same application? I-m using visual studio 2005 and C#
Thanks in advance
|
|
|
|
|
Are they persisted settings? If so, have you considered setting/reading registry key values in HKCU\Software\{mycompany}\{mysettings\{setting a}, etc? Or if the settings are persisted in an INI file local to the application exe, reading in that (assuming the INI is updated real time) and getting the settings from there?
Mike Poz
|
|
|
|
|
I have an ArrayList with numerical values in.
I want to be able to only have distinct items, either by getting rid of any duplicates, or copying single values over to a new array (whatever works).
e.g.
I have: 1, 2, 3, 3, 4, 5, 5, 5, 8, 9, 9
I want: 1, 2, 3, 4, 5, 8, 9
Unfortunately I can't figure out how to do this. Can someone please help?
|
|
|
|
|
There a couple of ways you could attack this, depending on speed and space considerations. Here they are theoretically:
1) Sort the array list, then go through and call ArrayList.RemoveAt to chop out any duplicates in a simple loop through the sorted array.
2) Copy the ArrayList over to another ArrayList item by item, but each time, before you add an item, call ArrayList.Contains to check if the NEW array already contains the value you are trying to add from the OLD array.
3) Copy the ArrayList over to a Hashtable item by item, making the key the items in your array, and each time call Hashtable.ContainsKey to check if you've already added a value from the array.
These were a couple of the ways I could think of. There are probably others and more efficient, but these will get the job done. I wouldn't recommend using number 3 unless time is a real consideration. Number 2 is going to take much longer if you have a long array, because this will be looping through the array as many times as you have items. Number 1 can be longer or shorter depending on the sort algorithm you have.
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Thanks!
For 2, I found a thing called ArrayList.BinarySearch. Would that make it more efficient?
E.g. Something like
myArrayListOne = original data;
myArrayListTwo = distinct data;
for (int i=0; i < myArrayListOne.Count-1; i++)
{
if (myArrayListTwo.BinarySearch(myArrayListOne[i] > 0))
{
myArrayListTwo.Add(myArrayListOne[i]);
}
}
Which probably won't work straight off, as it takes me a few tries to get things to work, but you get the idea.
So, would using BinarySearch like that be more efficient?
Also, are ArrayLists very effecient? Or should I be using, or converting the ArrayList to an Array as soon as possible?
|
|
|
|
|
Alexander Wiseman wrote: I wouldn't recommend using number 3 unless time is a real consideration.
What do you mean by that?
Alexander Wiseman wrote: 3) Copy the ArrayList over to a Hashtable item by item, making the key the items in your array, and each time call Hashtable.ContainsKey to check if you've already added a value from the array.
You dont need to use ContainsKey when adding in this case. You can simply use SetItem (indexer) for all the array elements.
|
|
|
|
|
leppie,
Thanks for your comments. I said I wouldn't recommend number 3 unless time was a consideration because I was unsure what overhead one might be pulling in by using a Hashtable to store the information. It seemed to me to be a roundabout way of doing it, and I wasn't comfortable with suggesting it as the most robust solution. On the other hand, it also seemed to me that using a Hashtable would be very fast, since looking up keys in a Hashtable is efficient. Please tell me if I'm not understanding something fundamental about Hashtables or whether you have a different opinion.
As regards your second point, I stand corrected. I should have realized that, in adding items to the Hashtable, one need not check if they are already there, because the same key cannot be repeated in the Hashtable!
Thanks again.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Do you have control over the items as they are being added to the ArrayList? If so, you could check the Contains method first to see if the ArrayList already contains the item.
Or sort the ArrayList and add the items to a new ArrayList. As you add the items, you sift out duplicates (untested):
public static ArrayList Filter(ArrayList items)
{
#region Guard
if(items.Count == 0)
{
return items;
}
#endregion
items.Sort();
object previousItem = items[0];
ArrayList result = new ArrayList();
result.Add(previousItem);
foreach(object obj in items)
{
if(!previousItem.Equals(obj))
{
result.Add(obj);
}
previousItem = obj;
}
return result;
}
|
|
|
|
|
Ahh, true, thanks. I keep getting stuck in one little 'thought process', and don't think outside it sometimes.
|
|
|
|
|
|
Troops,
I've read several messages in several places and what seems to be a simple task is not giving me much love. I'm simply trying to launch the default mail client in C#. I've tried the following:
string mailToAddress = "mailto:joe.mama@exception.net";
System.Diagnostics.Process.Start( mailToAddress );
and also...
string mailToAddress = "mailto:joe.mama@exception.net";
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = mailToAddress;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start();
Both give me the following rash (exception):
The requested lookup key was not found in any active activation context
* We're using version 1.1 of the Framework.
* We have a Help, About form that has a 'Customer Service' label on it. When the user clicks it we want to open the default mail client with the 'To' address filled-in. From that 'About' form is where we are trying to run the above code.
* I read an article that claimed switching the UseShellExecute to false would help. It got rid of that exeception and gave me a 'file not found' in it's place.
I've read articles about 'how easy this is' and other articles claiming a threading problem. It seems like it should be a simple thing to accomplish.
Any help is greatly appreciated. We're all counting on you.... Good luck.
Stretch
|
|
|
|
|
Hello Stretch,
I tested out the code you put in your question text: the second version, where you actually create a Process object, and it worked out fine: Thunderbird (my default email client) opened up without a problem, with a new mail addressed to joe.mama@exception.net.
This probably means that the issue you are having is caused by not having a default email client set, or not having one setup properly. The proper handler for the "mailto" keyword is actually defined in the Windows Registry. If you go to Start > Run and then type "regedit" you will be able to view the registry. Open up to "HKEY_LOCAL_MACHINE" and then go to the following path under there "SOFTWARE" > "Clients" > "Mail". Now you should have that registry key open (i.e. selected in the left pane). When that key is selected in the left pane, then in the right pane, you will see a value whose name is "(Default)" and whose value is your default mail client. Mine says "Mozilla Thunderbird". You may not have this set, which could be causing the problem. If it IS set, then continue reading!
Just a phrase like "Mozilla Thunderbird" is not enough to tell Windows what to do if it encounters the "mailto" keyword. Let's look a little deeper into the registry! Open up the key called "Mail" in the left pane and find the sub-key with the same name as the value of the "(Default)" key which you just found. For me, I have a key called "Mozilla Thunderbird". Alright, open that one up. You will probably see a variety of other keys, but the one we are interested in is "protocols" (it does not matter if it is capitalized or not). If you do not have that key, then that should explain your problem - Windows does not know what to do with the "mailto" protocol on your client. If you do have that key, keep reading!
Open up the "protcols" key and under it you should see "mailto". This is the key which will tell Windows how to deal with a mailto command. Open up that key as well, and you should get to a key called "shell". Under "shell" there should be a key called "open" and under that a key called "command". Select "command" in the left pane, and look at the various values in the right pane. There is probably only one listed, another "(Default)" value. Mine has this as the associated data: "C:\PROGRA~1\MOZILL~2\THUNDE~1.EXE -compose %1". This is the command which Windows executes whenever it sees "mailto".
I will quickly recap and you can then try and identify where your problem lies:
1) Inside the key "Clients" > "Mail" You should have the "(Default)" value set to a mail client on your machine.
2) There should be another key with that mail-client's name underneath the "Mail" key.
3) Inside that key, there should be the following set of keys: "protocols" > "mailto" > "shell" > "open" > "command"
4) The value called "(Default)" in the "command" key should be set to a valid executable with some command line parameters, like "-compose".
At each of these four places, you could have an invalid registry key or missing value. Check that and see if it is all in place. Reply to this message with the results of your finding, and then I will try to help you fix it.
Hope that helps start you out in the right direction!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hi Alexander,
Thanks for the thorough research. I should have mentioned that running "mailto:user@yahoo.com" (or similar) works from the Start, Run box. Outlook opens with the To: info filled in.
I checked all your points above just for kicks and I have data in all places. I'm using Outlook 2003 and the last entry had some cryptic parameters:
"C:\PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE" -c IPM.Note /m "%1"
Other than that, I think the rest is ok and like I said, it works from the Start, Run box... which is why this is driving me nuts.
I'll make a smaller test app and try it from there and let you know what I find. We've had some strange things happen with threading.. depending on where we spawn threads in the code. Our application is pretty complex and I'll try to step back and use small test app. We've heard some strange things with regard to threading in version 1.1 of the Framework.
I'll let you know what I found...
Thanks!
Stretch
|
|
|
|
|
Alrighty then!... I just did a quick tester application and used the same code I'm having problems with in our company's app. Works just peachy. As I mentioned, our company app is pretty complex and one thing we had to do was switch from STAThread to MTAThread to accommodate a legacy system in Europe on Windows 98 (gag). Anyways, I tried switching STA to MTA in the tester app and bingo... same exception.
We 'should' not need to support that legacy system in Win 98 and I'm looking into that... but does anyone know why I have this issue using MTAThread and this type of Process that I'm running?
Thanks,
Stretch
|
|
|
|
|
Stretch,
Thanks for your reply. This is a very interesting issue, to say the least! I do not know enough about the Multi-Threaded Apartment state to say for sure what is going on, but I'm guessing, by the error message, that it has something to do with not being able to access part of the registry, or accessing the wrong part of the registry when in a multi-threaded aparatment model. I need to do a few more searches for information about this; I hope it is documented somewhere.
In the meantime, if you want a quick and dirty workaround, you can run cmd.exe and execute the command that way. Since the Command Line Interpreter won't understand the "mailto" keyword, you have to use the "start" command to have it execute properly. This is the code I tried in a test application with the MTAThread attribute set, and it worked fine:
string mailToAddress = "mailto:joe.mama@exception.net";
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/C start " + mailToAddress;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start(); Like I said, it's a little bit ungainly, but it does work. If I think of anything else, I'll let you know.
Sincerely,
Alexander Wiseman
|
|
|
|
|
I wish to transfer a session state from one page to another. Is there a simple way to transfer the state without storing it and then taking it back out in some complex almost useless way?
Thanks for all the help!
|
|
|
|
|
i want to start programming neural nets using c#.
plz help me
|
|
|
|
|
|
|
|