Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
Hi guys

I'm not a .net developer, but I have a managed c++ app that I need to work on.
I need to find out the name of the .exe currently being run - if someone renames the app from abc.exe to def.exe then I need to be able to call something that tells me the running .exe is def.exe.

I've tried my luck with System::Assembly::GetExecutingAssembly()->FullName but it doesnt seem to be working as expected - my app retrieves settings from the registry - originally it was hard-coded to the original name of the app, but I want to be able to rename the app to something else and be able to use another set of config settings. When I rename the app and run it from explorer, it loads up the settings from the original registry key, rather than creating new settings for the new filename.

Worst case I'll call ::GetModuleFileName(NULL,,) and copy that into a System::String but there must be a .net function that can do this?

Adbot
ADBOT LOVES YOU

Fart Amplifier
Apr 12, 2003

beuges posted:

Hi guys

I'm not a .net developer, but I have a managed c++ app that I need to work on.
I need to find out the name of the .exe currently being run - if someone renames the app from abc.exe to def.exe then I need to be able to call something that tells me the running .exe is def.exe.

I've tried my luck with System::Assembly::GetExecutingAssembly()->FullName but it doesnt seem to be working as expected - my app retrieves settings from the registry - originally it was hard-coded to the original name of the app, but I want to be able to rename the app to something else and be able to use another set of config settings. When I rename the app and run it from explorer, it loads up the settings from the original registry key, rather than creating new settings for the new filename.

Worst case I'll call ::GetModuleFileName(NULL,,) and copy that into a System::String but there must be a .net function that can do this?


Can't you just pull the name of the program from the arguments passed into the main method?

biznatchio
Mar 31, 2001


Buglord

Fart Amplifier posted:

Can't you just pull the name of the program from the arguments passed into the main method?

Not in .NET, no. The string[] args passed to Main() doesn't include the executable name.

To the original question: System.Assembly.GetEntryAssembly().CodeBase will return the path to the originally-executed file in URI format (a file:// URL for local paths -- but since .NET applications can be run directly from an [url]http://[/url] location, it could also possibly be that).

It should also be in System.Environment.GetCommandLineArgs()[0], for a locally-executed app anyway; but that may or may not be a fully-qualified pathname, depending on how the app was executed.

biznatchio fucked around with this message at 12:40 on May 21, 2007

fankey
Aug 31, 2001

beuges posted:

Hi guys

I'm not a .net developer, but I have a managed c++ app that I need to work on.
I need to find out the name of the .exe currently being run - if someone renames the app from abc.exe to def.exe then I need to be able to call something that tells me the running .exe is def.exe.

I've tried my luck with System::Assembly::GetExecutingAssembly()->FullName but it doesnt seem to be working as expected - my app retrieves settings from the registry - originally it was hard-coded to the original name of the app, but I want to be able to rename the app to something else and be able to use another set of config settings. When I rename the app and run it from explorer, it loads up the settings from the original registry key, rather than creating new settings for the new filename.

Worst case I'll call ::GetModuleFileName(NULL,,) and copy that into a System::String but there must be a .net function that can do this?

If biznatchio's suggestions don't pan out you could try System::Process::GetCurrentProcess()->MainModule->FileName.

SLOSifl
Aug 10, 2002


I am pulling my hair out. I have a popup window class (much like the MSN 'toaster' windows), but everytime I create and display one, it takes focus from my main application. After creating the window, the program immediately attempts to refocus the main window (which is by no means ideal, even if it worked). Upon being displayed, the popup window again attempts to invoke the main window's Focus method (and I briefly tried to use BringToFront) to no avail.

A long time ago I came across a way to make a window unfocusable. I believe the Windows On Screen Keyboard uses this technique. Does anyone know a good way to solve my problem in .NET?

biznatchio
Mar 31, 2001


Buglord

SLOSifl posted:

A long time ago I came across a way to make a window unfocusable. I believe the Windows On Screen Keyboard uses this technique. Does anyone know a good way to solve my problem in .NET?

This blog post answers your question, and also gives a solution to your problem of a form taking activation focus when it's shown.

SLOSifl
Aug 10, 2002


biznatchio posted:

This blog post answers your question, and also gives a solution to your problem of a form taking activation focus when it's shown.
Very nice, thanks. That worked like a charm!

I came across a Win32 way to do it involving ShowWindow and an argument called SW_SHOWNOACTIVATE, but it still took focus.

edit: It seems that the window takes focus still, depending on some unknown factor. When the popup window is created as the result of an event outside the main thread, it is shown unfocused. When the window is created by the UI thread directly, it takes focus. In the case of the off-thread creation, the popup window is constructed and shown using Invoke.

SLOSifl fucked around with this message at 19:08 on May 21, 2007

biznatchio
Mar 31, 2001


Buglord

SLOSifl posted:

edit: It seems that the window takes focus still, depending on some unknown factor. When the popup window is created as the result of an event outside the main thread, it is shown unfocused. When the window is created by the UI thread directly, it takes focus. In the case of the off-thread creation, the popup window is constructed and shown using Invoke.

Does the SW_SHOWNOACTIVATE thing in combination with the WndProc() override work?

SLOSifl
Aug 10, 2002


When I used ShowWindow, the window wouldn't take focus, but it wouldn't run through my OnShown event handler. When the window is shown, it runs through code that fades it in from transparent to opaque. It also positions the window. I moved things around so that it called my positioning and fading code, using ShowWindow in there as well, and it started taking focus.

I have no idea what the hell is going on anymore. As far as I can tell, I'm telling the window in at least two ways to never take focus. Ever.

MrBishop
Sep 30, 2006

I see what you did there...

Soiled Meat
This may not be a (direct) programming question, but I'm writing a .Net 2.0 app that my client would like to be able to run off a network share. I remember seeing somewhere that i need to modify the security permissions of the app to allow it to run from the network, but other than that, are there any issues I should be aware of with allowing multiple users to run a .Net app off a share?

BryanGT
Oct 15, 2002

Goodnight, sweet prince.
^^^^^^^^^^^^^^^^^^

Why not use clickone?

http://msdn2.microsoft.com/en-us/netframework/aa497348.aspx

Fryedegg
Jan 13, 2004
Everquest killed my libido (and my cat). 8(
I have a GridView set up to display the results of a DAL query. I'm making the primary key column invisible. However, on row selection, I'd need to use the primary key as an argument for another method that populates a different table.

Unfortunately, if you set a column to not be visible, then the data of that column returns an empty string when using keyRow.Cells[x] property during a GridView_SelectedIndexChanged event. (Apparently it didn't do this in 1.1)

I've looked around this afternoon, but any answers I find on this are very cryptic. One is suggesting using an invisible template, but doesn't go into much detail. (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=226153&SiteID=1)

I'm fairly new to .NET and I'm finding this wayyyy more painful than it should be. Anyone familiar with a workaround?

Fryedegg fucked around with this message at 03:04 on May 22, 2007

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
I'm writing a very, very, very basic proof-of-concept FTP client library, just to learn C#/.NET. All the commands are hard-coded and it's kludgey to an amazing degree, but it seems to work. A couple of times.

I'm using PORT mode and the problem is, after running the program a couple of times in succession, the FTP server won't be able to connect to my listening socket. My listening socket doesn't seem to report any problems, and will happily sit waiting there forever for an incoming connection from the server, while my server reports "425 Can't open data connection." However, if I wait for about 5 minutes before trying again, it all works great for at least one or two more runs.

I've tried this against two different servers on two different machines (one local,) and gotten the same results, so I'm fairly sure it's a problem on my end.

The time-based component makes me think I'm not properly closing some connection, and I'm having to wait for a timeout for it to work again, but I call Close() on the TcpClient and Stop() on the TcpListener, so I'm not sure what else I can do.

You can see my code here: http://ace.pastey.net/37605 (line where it hangs is highlighted.) I know the code is utter crap, but like I said, this is just a learning proof-of-concept, so I'm not too concerned with it since it's all getting thrown out once it works (though if you see any fundamental theory flaws, please point them out.)

binary_hero
Oct 10, 2004

by Lowtax

Magicmat posted:

The time-based component makes me think I'm not properly closing some connection, and I'm having to wait for a timeout for it to work again, but I call Close() on the TcpClient and Stop() on the TcpListener, so I'm not sure what else I can do.

I have never written a FTP client, but it does definitely sound like something isn't being closed. It could be "foo", you don't seem to close that at all.

binary_hero
Oct 10, 2004

by Lowtax

Fryedegg posted:

I have a GridView set up to display the results of a DAL query. I'm making the primary key column invisible. However, on row selection, I'd need to use the primary key as an argument for another method that populates a different table.

Unfortunately, if you set a column to not be visible, then the data of that column returns an empty string when using keyRow.Cells[x] property during a GridView_SelectedIndexChanged event. (Apparently it didn't do this in 1.1)

I've looked around this afternoon, but any answers I find on this are very cryptic. One is suggesting using an invisible template, but doesn't go into much detail. (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=226153&SiteID=1)

I'm fairly new to .NET and I'm finding this wayyyy more painful than it should be. Anyone familiar with a workaround?

Try either setting the width of the column to be 0, using a ListView instead (yes, you have to add the items and columns yourself, but they typically look nicer and work better), or you can set the Tag property of the row if it has one.

biznatchio
Mar 31, 2001


Buglord

Magicmat posted:

I'm using PORT mode and the problem is, after running the program a couple of times in succession, the FTP server won't be able to connect to my listening socket. My listening socket doesn't seem to report any problems, and will happily sit waiting there forever for an incoming connection from the server, while my server reports "425 Can't open data connection." However, if I wait for about 5 minutes before trying again, it all works great for at least one or two more runs.

Try running "netstat" between runs, in the time window your app doesn't run properly. See if any of your sockets are being held open by the OS in FIN_WAIT state.

Also, try creating and starting your listener before sending the PORT command to the server. I suppose its possible the server is trying to connect immediately upon receiving the command, but you don't actually have a listener running at that point yet.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
Well, using netstat, I've found that my socket is being left in a TIME_WAIT state after the app exits. This raises two questions: Why is it doing this, and why doesn't the TcpClient complain when I use a port that is already being used?

After some more reading, I figured out that (despite what the MSDN examples seem to imply,) I should call Close() on the TcpClient's underlying NetworkStream. However, this doesn't seem to have fixed the problem in any way, so I'm still stumped at what I'm doing wrong.

Edit: When trying to do netstat -abv to see the call stack and process for the TIME_WAIT port, it just returns PID 0 (system) and no call stack, if that helps anybody. Also, as a side note, the both the port for the control connection and the data connection are stuck in TIME_WAIT, though the outgoing control connection works just fine if I try to run the app again with the port in that state, while the incoming data connection fails.

Does anybody with experience using TcpClient know the correct procedure for shutting it down?

Here's my updated code, if you want to see it.

Magicmat fucked around with this message at 00:24 on May 23, 2007

biznatchio
Mar 31, 2001


Buglord
In that case, you can set the reuse flag on the socket, which tells the OS that it's alright to hijack a socket in the close-wait state and reappropriate it for new use.

code:
TcpListener x = new TcpListener(/* parameters */);
x.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
x.Start();
By the way, this is not a .NET-related issue specifically, it's an issue common to all sockets, due to some on-close handshaking that the TCP protocol needs to do to guarantee reliability -- after a close the OS needs to keep the port reserved in case any closing handshake packets come in, within a certain timeout period. In C/C++, you'd work around this same issue by specifying SO_REUSEADDR when you set up your socket. The above snippet of code sets that very same flag on the socket underlying the TcpListener object.

If you want to make a robust FTP client though, instead of hardcoding your port to a certain value, you should just open a socket, letting the OS decide the local port number, then send that to the server. The reason you don't get the same problem with your TcpClient object is because what I just described in the last sentence is exactly what TcpClient does -- your local port number for the client connection is selected automatically by the OS, the port number you're supplying is the remote port, which is set up as a listener and can accept any number of incoming connections. (You can verify this by using netstat, you'll notice the remote port number is always the same, but the local port number appears to be random.)

biznatchio fucked around with this message at 02:00 on May 23, 2007

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

biznatchio posted:

In that case, you can set the reuse flag on the socket, which tells the OS that it's alright to hijack a socket in the close-wait state and reappropriate it for new use.

code:
TcpListener x = new TcpListener(/* parameters */);
x.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
x.Start();
By the way, this is not a .NET-related issue specifically, it's an issue common to all sockets, due to some on-close handshaking that the TCP protocol needs to do to guarantee reliability -- after a close the OS needs to keep the port reserved in case any closing handshake packets come in, within a certain timeout period. In C/C++, you'd work around this same issue by specifying SO_REUSEADDR when you set up your socket. The above snippet of code sets that very same flag on the socket underlying the TcpListener object.

If you want to make a robust FTP client though, instead of hardcoding your port to a certain value, you should just open a socket, letting the OS decide the local port number, then send that to the server. The reason you don't get the same problem with your TcpClient object is because what I just described in the last sentence is exactly what TcpClient does -- your local port number for the client connection is selected automatically by the OS, the port number you're supplying is the remote port, which is set up as a listener and can accept any number of incoming connections. (You can verify this by using netstat, you'll notice the remote port number is always the same, but the local port number appears to be random.)
Setting that option doesn't seem to have any effect. I still get a "425 Failed to establish connection" error from the server. As a side note, vsftpd seems to send that error right after the RETR command, while FileZilla Server will send a "150 Opening data channel for file transfer" and then send the 425. Both happen after I call Start() on the TcpListener but before I call AcceptTcpClient().

As for the port usage, one of the features that I hope to have is the ability for the user to specify which ports to use for inbound transfers as a way to get past NAT devices (so that they can forward a set of ports to their specific computer and make sure the ftp client always asks the server to connect to one of those ports.) In practice the range of ports will hopefully be larger than one, but even then I'd need a way to determine which ports are safe to use and which ones are otherwise occupied.

biznatchio
Mar 31, 2001


Buglord

Magicmat posted:

Setting that option doesn't seem to have any effect. I still get a "425 Failed to establish connection" error from the server. As a side note, vsftpd seems to send that error right after the RETR command, while FileZilla Server will send a "150 Opening data channel for file transfer" and then send the 425. Both happen after I call Start() on the TcpListener but before I call AcceptTcpClient().

Ok, I'm confused then. Try this, just to see if it affects anything... replace lines 35-52 with the following:

code:
    listener.Start();

    System.Threading.ManualResetEvent completeEvent = new ManualResetEvent(false);
    TcpClient server = null;

    listener.BeginAcceptTcpClient(delegate (IAsyncResult ar) {
        server = listener.EndAcceptTcpClient(ar);
        completeEvent.Set();
    }, null);

    foo.SendData("PORT 192,168,1,100,30,97\r\n");
    Console.WriteLine(foo.RecieveData());
    foo.SendData("RETR testing_file.del\r\n");
    Console.WriteLine(foo.RecieveData());
    StringBuilder data = new StringBuilder();
    Console.WriteLine("Listening for file transfer");
    completeEvent.WaitOne();

    Console.WriteLine("Connection accepted.");
Let me know if that makes any difference. This code will guarantee that the socket is actively waiting on an accept() on the socket while the incoming connection comes in -- to rule out it being a connection queue issue.

If it doesn't work and it still fails in the same way, run it until it hangs, and while it's running and hung, do a netstat and see if you even have a socket open on port 7777 in the LISTENING state.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
Nope, no luck. Works the first time, fails the second.

Here's the relevent output from netstat -a:
code:
  TCP    sol:3586               example.com:12886  TIME_WAIT
  TCP    sol:3587               example.com:12886  ESTABLISHED
  TCP    sol:7777               sol:0              LISTENING
(Sol being my machine, example.com being the server.)

That is taken from just after the client hangs waiting for a connection, using your revised code. Here's the relevent output between when I first run the client successfully but before I run it a second time (where it will hang):
code:
  TCP    sol:3591               example.com:12886  TIME_WAIT
Which is odd because that's the control connection, not the failing data connection. There doesn't seem to be anything in sol:7777 in the output at that time. That is also the only relevent entry after I close the hung client. Until that disappears, the client will continue to hang.

Magicmat fucked around with this message at 04:02 on May 23, 2007

poopiehead
Oct 6, 2004

Did you also write the server? I ran your code against a dreamhost ftp server and couldn't get it to hang.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

poopiehead posted:

Did you also write the server? I ran your code against a dreamhost ftp server and couldn't get it to hang.
Nope, I'm testing it against both vsftpd running on Linux and FileZilla Server running on Windows with the same results.

Hmm, maybe it's my router. I'm going to try removing that from the equation and seeing if it works.

Edit: Nope, removed the router and got the same thing. That's odd, though, that it's working for you and not for me. Did you run the program at least two times in relatively quick succession?

Edit 2: Just tried it against my webhosting's, 1&1, ftp server and still got the same errors. Curiouser and curioser.

Magicmat fucked around with this message at 04:59 on May 23, 2007

biznatchio
Mar 31, 2001


Buglord
Those netstat readings are exactly what was expected if it was working correctly. This is a perplexing problem, there's no reason it shouldn't be working.

Are you running any sort of personal firewall software that might be interfering with the connections? Do you have access to another machine to try running it on? Can you get a copy of ethereal and do some logging?

edit: Woah woah woah wait a minute. Problem identified: You're listening on a 192.168.* address, and connecting to servers on the internet. That means NAT is getting involved. (You mentioned this earlier but it didn't really register with me until now.) I would bet money on the fact that your NAT is getting confused because you're using the same port for your data connection across multiple control connections in a short period of time. NAT boxes have to do some special voodoo port forwarding magic to correctly map active mode FTP (since at the very least you can't really be telling the server that it needs to connect to 192.168.x.x because it'd never be able to connect back to you -- the NAT at least needs to rewrite your PORT command with your actual public IP, and it undoubtedly does some other magic too).

You said once it starts failing, it's like 5 minutes before it works again. Run it once, then again to get it to fail, then quickly reset whatever is performing your NAT and get it back online so you can try another connection within the 5 minute failure window. If it works, then you know it's a NAT issue, and actually changing the port number of your data connection would solve the problem (but completely derail your actual goal, of course).

If this ends up being the problem, is there a reason you couldn't use passive FTP instead?

biznatchio fucked around with this message at 05:19 on May 23, 2007

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
I tried it with my computer directly connected to the cable modem and got the same results. I'll try again by rebooting the router between connections, though I'm not sure the router will be able to reboot completly before the nominal reconnect error time times out by itself.

My router is running DD-WRT (and thus Linux with IPTables,) though I'm not sure if IPTables' FTP connection tracking works when the control port is something other than 21 on the server. Regardless, I'll try it again without the router, too.

I could use PASV, I just chose PORT because it involved listening, which would teach me more about how sockets work in .NET. Plus, I want the client to eventually work with PORT, so might as well get it working now.

Edit: Arghh, even with the router completly gone and with my own computer directly connected to the 'net, and even connecting to 127.0.0.1 I still get the same problem! This doesn't make sense. I don't have any software firewalls, or "Inernet Protection" software or anything else that might be messing with the TCP/IP stack.

Edit2: Although now a netstat in between the good and bad runs of the app show that port 7777 is stuck in a TIME_WAIT state only when I connect to 127.0.0.1. Connecting to a remote IP only leave the control connection in the TIME_WAIT state.

Edit3: Sniffing with Wireshark (Ethereal) shows that there is absolutely no activity to when the client sends the RECV command and when the server sends the 425 error. I don't know enough about socket programming to know whay implications this has, but there you go.

Edit4: I've figured out that it's the server's WAIT_TIME that's the key. By setting the ReuseAddress flag on the client socket at well, I've eliminated all WAIT_TIMEs on the client. However, running netstat (or, to be more precise, TCPView) on the server shows that it is still in WAIT_TIME mode connected to port 7777 of my machine, as well as for the control connection. So why does the control connection work and not the data, and how can I get them both to work all the time?

Interesting side note, while most of the time I can only run the client app once before it hangs the next time, every so often I can run it twice before it hangs. I don't know what the variable is during these times, though.

Magicmat fucked around with this message at 09:45 on May 23, 2007

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
Haha! Success! I just figured out that I had set vsftpd to always connect out from the same port in PORT mode. Changing it to let it connect from any port it wants now lets the client work! I guess FileZilla by default does this, too, which is why I was seeing the same behavior on both servers. (and, interestingly, whatever server 1&1 is using, since I got the same results from them, too.)

Question, though: Is it just a fact of life that a server won't be able to connect out from a port in WAIT_TIME mode to the same port it was just connected to? Is that correct, or is that behavior a bug somewhere? If it's supposed to be able to, why can't I do it, and how could I do it?

And, since it seems a decent amount of ftp servers out there only connect out in PORT mode from a single port, would the only way to avoid this while manually managing my local ports be to make sure I have enough ports in my "allowed ports" list so that I don't repeat a transfer from the same server to the same port before the average WAIT_TIME expires? Like, keep a stack of used ports somewhere for each server, and just go down that list each time I want to transfer something? That could get messy if each transfer is quick, I'd need a fair number of ports available. I know that other FTP clients don't seem to choke when I only let them have 10 ports and do a bunch of quick transfers, how do they do it?

Edit: I also notice my comment in my last message about being no more TIME_WAIT ports was a bit hasty. It seems even setting ReuseAddress on the control port, nearly every (but not all?) running of the app leaves one port in TIME_WAIT to the control port of the server, though this doesn't seem to happen with the data port. However, with the aforementioned change to vsftpd, this doesn't seen to affect the workings of the system.

Edit2: Also, the vsftpd server was on a machine doing NAT forwarding for a lan, and thus may have been subject to meddling by that. However, as I mentioned in a previous post, I did test against FileZilla with no router/NAT involved at all and got the error, so take that as you will.

Magicmat fucked around with this message at 10:37 on May 23, 2007

uXs
May 3, 2005

Mark it zero!
I'm doing an ASP.NET project where I have gridviews that show a list of records. These lists don't have to be edited. There are some columns where the value I have in the list is a foreign key. Naturally I want to display something else than a (for the user) meaningless key value.

What are some elegant methods of showing the user a value from the other table for each foreign key ? I'm using an objectdatasource as the datasource for the grid.

I was able to make a templatecolumn that has a dropdownlist, with another objectdatasource as the datasource, bound to the correct value. But using a dropdownlist in something that can't be edited is rather retarded. I want it to look like all the other columns, but with the value looked up from another table.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
Me again.

What is the best way to retrieve a file-type or folder's icon? I know about System.Drawing.Icon.ExtractImage(), but there are a few problems with that: First, I need to get a file type's icon given just its extension, not a full path (since I'm trying to create an Explorer-like details ListView based off the text directory listing from a FTP server.) Second is that it doesn't work for folders. Now, I could probably find a generic "folder" icon, but that doesn't work when the folder who's icon I want has a special icon (like My Pictures.) Additionally, I'd like the icon to be "faded" if the file or folder is hidden. Basically, I want the icons to look exactly how they do in Explorer's details view.

Also, the icons ExtractImage() gives me seem to look crappy when given to my ListView control. Observe my app on the left, and the FlashFXP FTP client on the right:

Only registered members can see post attachments!

Magicmat fucked around with this message at 10:54 on May 29, 2007

cowboy beepboop
Feb 24, 2001

Looks like the icons are being resized. Check there's enough room in that column to display them.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

Elky posted:

Looks like the icons are being resized. Check there's enough room in that column to display them.
Well, there's plenty of room in the ListView as a whole, and each columns is set to auto-size itself. I tried converting the icons it BitMap, resizing them and then passing them in on the image list, and that helped them look slightly less rear end, but it still didn't get to the heart of the problem. For example, look at the icon for AutoTuneScript.dll. In my app, it has a weird blocky drop shadow looking thing, while FlashFXP doesn't have that. And _default.pif in my app looks squished horizontally.

It looks like FlashFXP is able to retrieve icons that where designed for 16x16, while my app, using ExtractImage(), is getting larger icons and simply resizing them. However, ExtractImage() doesn't seem to support extracting any paticular size of icons.

wwb
Aug 17, 2004

uXs posted:

I'm doing an ASP.NET project where I have gridviews that show a list of records. These lists don't have to be edited. There are some columns where the value I have in the list is a foreign key. Naturally I want to display something else than a (for the user) meaningless key value.

What are some elegant methods of showing the user a value from the other table for each foreign key ? I'm using an objectdatasource as the datasource for the grid.

I was able to make a templatecolumn that has a dropdownlist, with another objectdatasource as the datasource, bound to the correct value. But using a dropdownlist in something that can't be edited is rather retarded. I want it to look like all the other columns, but with the value looked up from another table.

What is underneath the ObjectDataSource? A typed dataset or a real object?

If it is a typed dataset, you could select the appropriate bits of the child table and then create a data relation and use that to hook up the rows and display pretty stuff.

If it is a real object, then things can be a bit trickier unless you want to "deep load" everything from the get go.

DLCinferno
Feb 22, 2003

Happy

Magicmat posted:

Well, there's plenty of room in the ListView as a whole, and each columns is set to auto-size itself. I tried converting the icons it BitMap, resizing them and then passing them in on the image list, and that helped them look slightly less rear end, but it still didn't get to the heart of the problem. For example, look at the icon for AutoTuneScript.dll. In my app, it has a weird blocky drop shadow looking thing, while FlashFXP doesn't have that. And _default.pif in my app looks squished horizontally.

It looks like FlashFXP is able to retrieve icons that where designed for 16x16, while my app, using ExtractImage(), is getting larger icons and simply resizing them. However, ExtractImage() doesn't seem to support extracting any paticular size of icons.
To solve the blocky shadow, try doing this to your image list (also in the designer I think):

this.imageListIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;

I've got some code to pull icons but I doubt its going to do anymore than ExtractImage. You'll probably have to reshade the icons yourself when a file is hidden regardless of where you get the icon from.

Here's the code:

code:
//Need these includes
using System.Runtime.InteropServices;
using Microsoft.Win32;

//Define this struct and class
    [StructLayout(LayoutKind.Sequential)]
    public struct SHFILEINFO
    {
        public IntPtr hIcon;
        public IntPtr iIcon;
        public uint dwAttributes;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szDisplayName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
        public string szTypeName;
    };

    class Win32
    {
        public const uint SHGFI_ICON = 0x100;
        public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
        public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

        [DllImport("shell32.dll")]
        public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
    }

//Use inside of a class like so:
class Sample
{
        public void Icon {
                        IntPtr hImgSmall;
                        SHFILEINFO shinfo = new SHFILEINFO();
                        hImgSmall = Win32.SHGetFileInfo(file, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);

                        //Use this to get the large Icon
                        //hImgLarge = SHGetFileInfo(fName, 0, 
                        //	ref shinfo, (uint)Marshal.SizeOf(shinfo), 
                        //	Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);

                        Icon myIcon = Icon.FromHandle(shinfo.hIcon);
                        imageListIcons.Images.Add(myIcon);
                        myIcon.Dispose();
        }
}
edit:

Path to the file is "file":

hImgSmall = Win32.SHGetFileInfo(file, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON)

SLOSifl
Aug 10, 2002


You can call SHGetFileInfo like this instead:
code:
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0;
public const uint SHGFI_SMALLICON = 0x1; 
public const uint SHGFI_USEFILEATTRIBUTES = 0x10; 
public const uint FILE_ATTRIBUTE_NORMAL = 0x80;

SHGetFileInfo(file, FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), 
   SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)
With SHGFI_USEFILEATTRIBUTES, the filename doesn't have to be valid.

poopiehead
Oct 6, 2004

Anyone know a good tool that can convert word documents to pdf? I'm asking here because I'd prefer a .NET library that I can call from my ASP .NET code, but anything wtih a command line interface will work...

Fiend
Dec 2, 2001

poopiehead posted:

Anyone know a good tool that can convert word documents to pdf? I'm asking here because I'd prefer a .NET library that I can call from my ASP .NET code, but anything wtih a command line interface will work...
Have you investigated the google yet?

Has anyone worked with any of these before?

The Noble Nobbler
Jul 14, 2003

Fryedegg posted:

I have a GridView set up to display the results of a DAL query. I'm making the primary key column invisible. However, on row selection, I'd need to use the primary key as an argument for another method that populates a different table.

Unfortunately, if you set a column to not be visible, then the data of that column returns an empty string when using keyRow.Cells[x] property during a GridView_SelectedIndexChanged event. (Apparently it didn't do this in 1.1)

Have you tried using the SelectedDataKey collection? Perhaps it uses the underlying datasource rather than the presentation collection. You would need to set the column name for the datakey in the <gridview> decleration

poopiehead
Oct 6, 2004

Fiend posted:

Have you investigated the google yet?

Has anyone worked with any of these before?

The google pretty much ends up giving all horrible freeware/shareware lists or services that do online conversion for you, so I was hoping someone here actually had a positive experience with something. I'm sure something in the google results I've gotten is good but it's impossible to find.

uXs
May 3, 2005

Mark it zero!

wwb posted:

What is underneath the ObjectDataSource? A typed dataset or a real object?

If it is a typed dataset, you could select the appropriate bits of the child table and then create a data relation and use that to hook up the rows and display pretty stuff.

If it is a real object, then things can be a bit trickier unless you want to "deep load" everything from the get go.

It's an object. I ended up putting the parts of the foreign table I want to view in the object itself. It seemed the easiest way and it's not that much overhead.

Perhaps I should make some functions that do get the extra info and some others that don't, to make it more maintainable, I dunno.

Fiend
Dec 2, 2001

poopiehead posted:

The google pretty much ends up giving all horrible freeware/shareware lists or services that do online conversion for you, so I was hoping someone here actually had a positive experience with something. I'm sure something in the google results I've gotten is good but it's impossible to find.
My apologies.

It sure would be useful to have Adobe Acrobat Document (.PDF) show up in the list of file types in the Save As dialog in word.

Adbot
ADBOT LOVES YOU

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

havelock posted:

untested code:
code:
string cell1, cell2;
using(SqlConnection conn = new SqlConnection("conn string"))
{
  using(SqlCommand cmd = new SqlCommand("SELECT cell1, cell2 FROM table", conn))
  {
    conn.Open();
    using(SqlDataReader rdr = cmd.ExecuteReader())
    {
      if(!rdr.Read()) throw new InvalidOperationException("Your query didn't return a row!!"); //argument exception may be more appropriate
      cell1 = rdr.GetString(0);
      cell2 = rdr.GetString(1);
    }
  }
}

//do stuff with cell1, cell2

Hey, I apologize for the lateness in this response, but it turns out that I had to completely scratch my website and start a whole new program, which means I didn't even need this :downs:.

But, I wanted to thank you for posting this :).

  • Locked thread