|
If you only need the names of the files you can call the System.IO.Direcoty.GetFiles method which returns an array of string.
If you need more information you first instatiate an DirectoryInfo object and then call the instances GetFiles method which returns an array of System.IO.FileInfo.
Sample:
<code>System.IO.DirectoryInfo windowsDir = new System.IO.DirectoryInfo(@"C:\windows\");
System.IO.FileInfo[] filesInDir = windowsDir.GetFiles("*.*");
</code>
/cadi
24 hours is not enough
|
|
|
|
|
Thanks man...It worked!
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
We have an app made in C# which promtes users for a sql query at run time, this has become difficult for the users but we were thinking of an easy to use query builder to integrate; instead of writing from scratch we were were wondering if there were available tools to use ??
|
|
|
|
|
I am making a windows form and I would like to place buttons or icons that will start other applications from the form. I am programming this is c#. I would like to know what I need to do to get the button to start other programs .exe
Thanks for any help
|
|
|
|
|
Use the System.Diagnostics.Process newProcess = System.Diagnostics.Process.Start(exe, params) method in the buttons OnClick handler.
If you need more control over the appearance of the new application you shoud first fill a ProcessStartInfo and then call the System.Diagnostics.Process newProcess = System.Diagnostics.Process.Start(startupInfo) .
To wait for the process to finish use the following code:
System.Diagnostics.Process newProcess = System.Diagnostics.Process.Start(@"c:\windows\notepad.exe");
System.Threading.WaitHandle processHandle = new System.Threading.AutoResetEvent(false);
processHandle.Handle = newProcess.Handle;
processHandle.WaitOne();
/cadi
24 hours is not enough
|
|
|
|
|
|
I translated several Windows Forms from german to english. I simply set the Localizable property in the Windows Forms Designer to true and changed the Language property to German.
But I made a mistake: The language "(Default)" now contains German texts and the language "German" contains the English texts.
Question: Is there a way to "swap" this without the need to painfully edit the .resx files by hand?
--
Affordable Windows-based CMS for only 99 €: try www.zeta-producer.com for free!
|
|
|
|
|
Public Function isChar(Expression As Variant) As Boolean
Dim str, I, length, ch
I = 1
str = Expression
length = Len(str)
While (I <= length)
ch = Mid(str, I, 1)
If Asc(ch) >= Asc("a") And Asc(ch) <= Asc("z") Or _
Asc(ch) >= Asc("A") And Asc(ch) <= Asc("Z") Or _
Asc(ch) = Asc(" ") Or Asc(ch) = Asc(".") Or _
Asc(ch) = Asc("-") Or Asc(ch) = Asc(",") Then
isChar2 = True
Else
isChar2 = False
Exit Function
End If
I = I + 1
Wend
End Function
Thanks
Monica
|
|
|
|
|
Have you even looked here?[^]
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|
|
public bool IsCharacter(string expression) {
bool success = false;
foreach(char c in expression) {
if(Char.IsDigit(c)) {
success = false;
break;
}
}
}
WM.
What about weapons of mass-construction?
|
|
|
|
|
Beside the fact your function returns nothing and wouldn't even compile (unless I add an extra return success - but in this case it always return false no matter what input you give to it), the IsDigit test is not even close to what the code of the op tested.
|
|
|
|
|
A line for line translation. Very quick and dirty, there is probably more efficent ways to do this.
public bool IsChar(string input)
{
bool isChar = true;
for(int loop = 0; loop < input.Length; loop++)
{
if((input[loop] >= 'A' && input[loop] <='Z') || (input[loop] >= 'a' && input[loop] <='z')
|| input[loop] == ' ' || input[loop] =='.'
|| input[loop] == '-' || input[loop] == ',')
{
isChar = true;
}
else
{
isChar = false;
break;
}
}
return isChar;
}
Michael
CP Blog [^] Development Blog [^]
|
|
|
|
|
I have a project where I must send data to a remote FTP server using an Active FTP connection. I'm able to connect to the remote server fine, but when I send the "POST" command, the socket is not connecting. I get the following exception error:
"A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied"
I have looked all over the net for an example of sending the FTP "POST" command, but haven't found anything. What am I doing wrong? Working examples would be greatly appreciated.
Here's the code snippet I'm trying to use (let me know if you need more information):
private string GetPortParameters(int localPort)
{
string localHost = Dns.GetHostName();
IPAddress localIPAddress = Dns.Resolve(localHost).AddressList[0];
string strLocalIPAddress = localIPAddress.ToString();
strLocalIPAddress = strLocalIPAddress.Replace('.',',');
int portParam1 = ( 0xff00 & localPort ) >> 8;
int portParam2 = ( 0xff & localPort ) ;
string portParameters = strLocalIPAddress + "," + portParam1 + "," + portParam2;
return portParameters;
}
private int GetPort()
{
if ( dataPort > 30000 )
{
dataPort = 10000;
}
return dataPort++;
}
private Socket CreateActiveDataSocket()
{
int thePort = GetPort();
string portParams = GetPortParameters(thePort);
Socket portSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(Dns.Resolve(Dns.GetHostName()).AddressList[0], thePort);
portSocket.Bind(ep);
portSocket.Listen(4);
SendCommand("PORT "+portParams);
SendCommand("STOR "+Path.GetFileName("C:\\somefilename.txt"));
portSocket.Accept();
// sending the socket back to the caller to transfer (upload) the file
return portSocket;
}
Eddie
|
|
|
|
|
I've written a full featured FTP client in java, The only command to upload stuff, as far as I know, is STOR. Before sending the STOR command you will need the PORT command. The following steps need to be done:
1. Make a socket that listens on a random port (use port 0 to initialize and get the actual port after the initialisation)
2. Send the PORT command.
3. Read the response and check if it's ok
3. Send the STOR command.
4. Write the file to the socket you created.
5. Read the response of the server and check if it's ok
It should work this way
WM.
What about weapons of mass-construction?
|
|
|
|
|
Thanks for the response, WM. The problem occurs in step 4 of your post. When I try to the file to the socket I created, I get the error that I previously posted. I need to know why the connection is not being established after sending the PORT command to the server.
Eddie
|
|
|
|
|
Are you behind a firewall/proxy something like that? It seems like the server couldn't connect to your socket. Check if the response on the STOR command is 150. If it isn't the server can't connect to your listening socket.
An alternative on the port command would be the PASV command in which case you connect to the server to post your file, instead of the server connecting to you.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Yes, I do get a 150 response once the STOR command is sent. I have no problem with the PASV command at all.
This is what I do for PASV (this works):
1. Connect to FTP server w/ Username/password
2. Send the PASV command and read the response from the server
3. I parse out the IP Address and Port sent by the server in step 2
4. Create a new socket with IP/Port and connect to it.
5. Send the STOR command
6. Send bytes to upload file on the connection created in step 4
This is what I assume I should be doing for PORT:
1. Connect to FTP server w/ Username/password
2. Retrieve local IP and generate random port #
3. Create new socket with IP/Port from step 2, Bind and Listen
4. Send the PORT command with the IP/Port generated in step 2 (I receive "200 Port command successful" from server)
This is where I'm unclear on what to do next. I'm assuming that the server will automatically connect to the port I just sent, but it doesn't seem to.
5. Send the STOR command (receive 150 response from server)
6. Upload file on connection that I'm listening on (Error occurs here).
The reason I'm trying to do it this way:
Our automated FTP program has been failing to send files to one of our clients in Passive mode. After we contacted them they asked that we try sending the files non-passive. What I find odd is that we receive a response from their server when sending the PASV command, but we can't connect to it. In fact, we can't even ping it. So, you might be right in that it could be a firewall issue on their end. Nevertheless, I was still tasked to get Active file transfers to work, but can't even do it on our local servers.
Any thoughts?
Thanks, Eddie
|
|
|
|
|
Are you writing a FTP server or a client? Your CreateActiveDataSocket() function attempts to listen on the specified port and host and then immediately does a SendCommand
Assuming you're writing a client, the correct code would be
private void ConnectToServer()
{
Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
socket.Connect(new IPEndPoint(Dns.Resolve(Dns.GetHostName()).AddressList[0], 20));
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks Senthil. I'm writing an FTP Client. Assume that I'm already connected to the FTP server. After connecting, I want to FTP a file in Active mode. In order to do so, I create a new socket with my local IP and a random port and listen to it. I then send the "POST 192,168,xxx,xxx,xxx,xxx" command to the server which has my local ip and random port I just generated that I want the server to connect to. The problem is that it doesn't seem that the server ever connects with the IP and port that I sent, hence, the error in my original post. How do I make the server connect to my IP/port? I know I'm missing something.....
Thanks again for your help!
Eddie
|
|
|
|
|
I've never heard of the POST command. It doesn't seem to be a standard FTP command?
AFAIK, you don't need to create a local server socket on a random port and list on it. And the server won't attempt to connect to your client, it's the client who'll connect to the server.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
i want the title bars of both forms to show active at the same time. In WindowsXP default, both title bars would be blue instead of one being blue and the other form fading to light blue, it is possible (overriding windows messaging) i know, but how?
Can someone indicate me how?
|
|
|
|
|
Sasuko wrote:
it is possible (overriding windows messaging) i know, but how?
Actually I don't think it is possible at all. You could paint your title bar the same color even if it is inactive, but getting Windows to paint the caption as active when it isn't, no way. Only one window is active by definition.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi, I have a user thread and I need to tell it to run some code in the GUI thread. I was thinking that maybe I would use SendMessage and create a message handler for this but it sounds like more of a C/C++ way of doing it. Is there something in C# line this? Kind of like java has SwingUtilities.invokeLater()
-- Rocky Dean Pulley
|
|
|
|
|
Actually SendMessage is not directly implemented in the CLR.
You should use the BeginInvoke to call code in the UI thread from another thread.
Google for BeginInvoke and UI or read this article: http://www.codeproject.com/csharp/winformthreading.asp[^]
/cadi
24 hours is not enough
|
|
|
|
|
You can use BeginInvoke and Invoke on the System.Windows.Forms.Control class.
This[^] article explains the gory details.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|