473,503 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the file and path information.

7 New Member
Hello,
I'm a beginner for vb.net. Now i have to create a ftp function that allow me to right click on a file and click on the option on the right click menu to ftp the file to a server. Can anyone teach me how to get the file and path information when right on the file like winzip or winrar. Then i also facing a problem for allow me to ftp a folder and the content inside the folder to a server by using vb.net 2005 FtpWebRequest.
Mar 26 '07 #1
8 2458
channaJ
67 New Member
Hello,
I'm a beginner for vb.net. Now i have to create a ftp function that allow me to right click on a file and click on the option on the right click menu to ftp the file to a server. Can anyone teach me how to get the file and path information when right on the file like winzip or winrar. Then i also facing a problem for allow me to ftp a folder and the content inside the folder to a server by using vb.net 2005 FtpWebRequest.

Hi Hengiccs,

Sorry but I can't understand the first part of your problem. From where are you gonna access the file path?

In the second case, you cannot FTP a folder. You have to send the files seperately to the server. The following code will help you on this.

Expand|Select|Wrap|Line Numbers
  1. string CompleteFTPPath = "ftp://channaj/test.txt";
  2. string CompleteLocalPath = "D:\MyTests\test.txt";
  3.  FtpWebRequest FtpRequest = (FtpWebRequest)WebRequest.Create(CompleteFTPPath);
  4.             FtpRequest.Method = WebRequestMethods.Ftp.UploadFile;
  5.             FtpRequest.Proxy = null;
  6.  
  7.             Stream requestStream = FtpRequest.GetRequestStream();
  8.             FileStream fileStream = File.OpenRead(CompleteLocalPath);
  9.             byte[] buffer = new byte[fileStream.Length];
  10.             fileStream.Read(buffer, 0, buffer.Length);
  11.             fileStream.Close();
  12.             requestStream.Write(buffer, 0, buffer.Length);
  13.             requestStream.Close(); 
In this code CompleteFTPPath is the complete path of the file in the FTP server. CompleteLocalPath is the complete path of the file in the local machine.

If you want to send a list of files, you have to call this code inside a loop. You cannot FTP a folder.
Mar 26 '07 #2
Hengiccs
7 New Member
Hi Hengiccs,

Sorry but I can't understand the first part of your problem. From where are you gonna access the file path?

In the second case, you cannot FTP a folder. You have to send the files seperately to the server. The following code will help you on this.

Expand|Select|Wrap|Line Numbers
  1. string CompleteFTPPath = "ftp://channaj/test.txt";
  2. string CompleteLocalPath = "D:\MyTests\test.txt";
  3.  FtpWebRequest FtpRequest = (FtpWebRequest)WebRequest.Create(CompleteFTPPath);
  4.             FtpRequest.Method = WebRequestMethods.Ftp.UploadFile;
  5.             FtpRequest.Proxy = null;
  6.  
  7.             Stream requestStream = FtpRequest.GetRequestStream();
  8.             FileStream fileStream = File.OpenRead(CompleteLocalPath);
  9.             byte[] buffer = new byte[fileStream.Length];
  10.             fileStream.Read(buffer, 0, buffer.Length);
  11.             fileStream.Close();
  12.             requestStream.Write(buffer, 0, buffer.Length);
  13.             requestStream.Close(); 
In this code CompleteFTPPath is the complete path of the file in the FTP server. CompleteLocalPath is the complete path of the file in the local machine.

If you want to send a list of files, you have to call this code inside a loop. You cannot FTP a folder.
===================

Dear channaJ ,
Really thanks for your help, actually the first part of my problem is, i have to add an option click on my right click menu after i had installed my deployed program. It's just look like those winzip program, so now what i want to do is, when i right click on a file (file highlighted) or a folder then the right click menu will pop out. In order that i can send the file to a server, i will click on the option on the right click menu then a form with some information and a send button will pop out. When i click on send button the file will be ftp to the server. Inside my code i have to know where the files located at,(path information) then i just can get the file information and send it out. So, i have to get the file information when i right click on it, then pass the information to my program. Really sorry for i don't know how to explain on it, because my english not good enough. Thanks again for your kindness.
Mar 26 '07 #3
channaJ
67 New Member
===================

Dear channaJ ,
Really thanks for your help, actually the first part of my problem is, i have to add an option click on my right click menu after i had installed my deployed program. It's just look like those winzip program, so now what i want to do is, when i right click on a file (file highlighted) or a folder then the right click menu will pop out. In order that i can send the file to a server, i will click on the option on the right click menu then a form with some information and a send button will pop out. When i click on send button the file will be ftp to the server. Inside my code i have to know where the files located at,(path information) then i just can get the file information and send it out. So, i have to get the file information when i right click on it, then pass the information to my program. Really sorry for i don't know how to explain on it, because my english not good enough. Thanks again for your kindness.
Ah...you are gonna play with the registry then. OK.

Hope you have created the particular registry keys. What you have to do here is passing the file path from the registry, when you are invoking your application. You can access this value from the main method of your app.

Add String[] args as a parameter of your main method. the file path will come as an element in args array.

You can pass the file path by adding "%L" element at the end of the path of the exe in the registry.

Hope this will make sence.:) Let me know if not.
Mar 27 '07 #4
Hengiccs
7 New Member
Ah...you are gonna play with the registry then. OK.

Hope you have created the particular registry keys. What you have to do here is passing the file path from the registry, when you are invoking your application. You can access this value from the main method of your app.

Add String[] args as a parameter of your main method. the file path will come as an element in args array.

You can pass the file path by adding "%L" element at the end of the path of the exe in the registry.

Hope this will make sence.:) Let me know if not.
================================================

Dear channaJ,
Ohh, thanks for reply me again. But really sorry for i not really understand how to do it? is it i have to add %L in the registry key value like ( C:\Program Files\TechStudioUV\Transfer files\Ftpfile.exe%L ). if yes, in the main method how to i get the file information? is it when i start run my program in the part of form1_load? Again, thank you very much.
Mar 27 '07 #5
channaJ
67 New Member
================================================

Dear channaJ,
Ohh, thanks for reply me again. But really sorry for i not really understand how to do it? is it i have to add %L in the registry key value like ( C:\Program Files\TechStudioUV\Transfer files\Ftpfile.exe%L ). if yes, in the main method how to i get the file information? is it when i start run my program in the part of form1_load? Again, thank you very much.
This is how you should add it to your registry key.

C:\Program Files\TechStudioUV\Transfer files\Ftpfile.exe "%L"

Once you do this, the path of the file on which you right clicked, is passed as a parameter to the Main() method of your programe. By default your Main() method does not take any parameter. So edit your Main() method as follows.

Expand|Select|Wrap|Line Numbers
  1. static void Main(String [] args)
  2. {
  3.    string filePath = args[0];
  4. }
Clear now ? Let me know if not.

Regards
Channa
Mar 28 '07 #6
Hengiccs
7 New Member
This is how you should add it to your registry key.

C:\Program Files\TechStudioUV\Transfer files\Ftpfile.exe "%L"

Once you do this, the path of the file on which you right clicked, is passed as a parameter to the Main() method of your programe. By default your Main() method does not take any parameter. So edit your Main() method as follows.

Expand|Select|Wrap|Line Numbers
  1. static void Main(String [] args)
  2. {
  3.    string filePath = args[0];
  4. }
Clear now ? Let me know if not.

Regards
Channa
===================

Dear channaJ,
Thanks channaJ. But it seem like i still have problem here. The VB.net 2005 don't have the startup object with Sub Main(). Only if, when i uncheck the checkbox of Enable application framework in the my project and put my sub main() to a new module it just will run the sub main(). When i try to right click on a file to pass the path information to my program, it pop up a error messagebox with path information and a warning "Access is denied". Then i not sue whether the sub main() for vb.net that i code is correct or not. e.g:

Public Sub Main(ByVal agrs1() As String)
Dim filepath As String = agrs1(0)
MsgBox(filepath.ToString)
End Sub

Best Regard
Hengiccs
Mar 28 '07 #7
channaJ
67 New Member
===================

Dear channaJ,
Thanks channaJ. But it seem like i still have problem here. The VB.net 2005 don't have the startup object with Sub Main(). Only if, when i uncheck the checkbox of Enable application framework in the my project and put my sub main() to a new module it just will run the sub main(). When i try to right click on a file to pass the path information to my program, it pop up a error messagebox with path information and a warning "Access is denied". Then i not sue whether the sub main() for vb.net that i code is correct or not. e.g:

Public Sub Main(ByVal agrs1() As String)
Dim filepath As String = agrs1(0)
MsgBox(filepath.ToString)
End Sub

Best Regard
Hengiccs

Hi Hengiccs,

Since VB.net doesn't give you a Sub Main() by default, what you have done is correct. As far as I understand the problem you are having now is something else. Check the permisions you have for the particular folder. Check permissions you have for the registry. Check whether your registry key is in order by calling a different exe. Do some experiments. ( I myself tried this with VB.net after your last reply. This worked just fine in my machine.) I think you are almost there. All the best.

Regards
Channa
Mar 28 '07 #8
Hengiccs
7 New Member
Hi Hengiccs,

Since VB.net doesn't give you a Sub Main() by default, what you have done is correct. As far as I understand the problem you are having now is something else. Check the permisions you have for the particular folder. Check permissions you have for the registry. Check whether your registry key is in order by calling a different exe. Do some experiments. ( I myself tried this with VB.net after your last reply. This worked just fine in my machine.) I think you are almost there. All the best.

Regards
Channa
=======================
Dear Channaj

ohh..., i will try to check for it now. i really feel appreciate for your help. Thanks a lot. :D

Best regard
Hengiccs
Mar 28 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2917
by: Bill Burwell | last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade tool to do the conversion - and it left me a lot of little code things to do. Did those code things and got my app to...
3
26239
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
1925
by: karunakar | last post by:
Hi All I am not able to read the class name I want read the particular class name string path = System.Configuration.ConfigurationSettings.AppSettings; string className = path + ".User";...
8
2696
by: Peter | last post by:
I'm trying to write a proceedure that will delete a file completely off a hardrive. I just don't want to kill the file. I want to rewrite over the data with 1's and 0's 8 times. Anyone have an...
2
1637
by: james troy | last post by:
I am trying to use a form that is usually used for file uploads to obtain a path/filename. The form I'm using is: <form id="f1" action="e.php" method="get"> <input type="hidden"...
1
3712
by: lactaseman | last post by:
While I know this is not the correct venue... I realize this is of little to no importance to most out there... however, if I had found this in my initial searches, I would have used this. So, as...
1
6439
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
10
2276
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
0
1993
by: Steve | last post by:
Hello- Your assistance with this issue is greatly appreciated. Environment: - Load-balanced IIS 6.0 servers (Win2003) - web servers point (via UNC path) to a Microsoft File Cluster on...
1
47347
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.