Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi huys,

how to list serial ports in my pc in ASP.NET which has uploaded to the website ?

when i tried

string[] ports = SerialPort.GetPortNames();

foreach (string item in ports)
{
ListBox1.Items.Add(item);
}

this just list ports listed on the server of website..
Posted
Comments
Keith Barrow 11-Mar-13 9:13am    
It will: the code is running on the server so it gets the ports on the server. You will need to investigate how to do this on the client side. I Googled "Javascript list serial ports" and got several promising results (this isn't something I've ever had to do- and why I haven't added an answer). It looks like JavaScript won't do this out of the box (a good thing in my view, it seems a bit of a security risk), but there is activeX that seems to do what you want.
It seems a pretty unusual thing to want to do however.
beratxt 11-Mar-13 9:26am    
can u give an example forcreatihg activeX ? how can i do it basically?

thanx for helping..
Keith Barrow 11-Mar-13 9:27am    
I really can't help much more, as I said I've not done this sort of thing before.
See Original Griff's reply. Th activeX solution only works in IE, and even then only if activeX is turned on. Personally, I think what you are doing has a "bad smell" about it (i.e. why would you want to list these port in a website, it feels like there is probably something wrong with the design if you are trying to do this) and is probably more suited to a full desktop application
[no name] 11-Mar-13 9:14am    
You would have to write some client side code to get that information.

1 solution

You can't. Or at least, you can't in 99% of circumstances.

C# code runs on teh server only - so it will alwasy report the server capabilities - it cannot access the client hardware for security reasons.

The only way to do it is to run software on the client PC to enumerate the ports - and you can't do that from the server very easily. The "normal" way to do something like this would be to create an ActiveX control, but there are a few problems with this approach:
1) They only work with IE
2) Even when the client is running IE, ActiveX controls are turned off by default.

If this is just a general "it'd be nice to do this" then drop it - it just isn't worth the time and trouble it will give you to get any generic solution running. And any website which asked me to "please run this software I am sending you" would go straight on my black list of banned sites.
 
Share this answer
 
Comments
beratxt 12-Mar-13 13:44pm    
No , just my customers will be able to use the system.So , ı WONT HAVE A PROBLEM such as banning or another..
If im able to write any activex code , will i be able to rerach this Acticex control using ASP.NET ?

Can u give imformation briefly ?
Thanks again for your helping.
OriginalGriff 12-Mar-13 14:59pm    
Google can:
https://www.google.co.uk/search?q=activeX+c%23&aq=f&oq=active+X+c%23&aqs=chrome.0.57j0l3j62l2.3172&sourceid=chrome&ie=UTF-8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900