473,657 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to move file to folder using vb.net

29 New Member
Hi, i would like to move a selected files to a folder using vb.net.

I currently have this code

If File.Exists("C: \Documents and Settings\055949 x\transfer\text .txt") And Not File.Exists("C: \Documents and Settings\055949 x\transfer\text .txt") Then

File.Move("C:\D ocuments and Settings\055949 x\transfer\text .txt", "C:\Documen ts and Settings\055949 x\Desktop\AES file\transfer\t ext.txt")
Label1.Text = ("File moved!")
Else
Label1.Text = ("File does not exist")
End If

How to i make it sure that i will be able to move different files without having to write the full directory of the file? I need to move the files that had been display on gridview.

p.s I'm using vb.net 2005
Mar 30 '07 #1
12 22834
RedSon
5,000 Recognized Expert Expert
You can use relative directory locations like . and ..
Mar 30 '07 #2
fanoftvb
29 New Member
thanx for the reply. Can u show me how to do it caz i'm actually quite new to vb.net?
Mar 30 '07 #3
RedSon
5,000 Recognized Expert Expert
thanx for the reply. Can u show me how to do it caz i'm actually quite new to vb.net?
Assuming that your code executable is running in the directory C:\Documents and Settings\055949 x\ directory...

Expand|Select|Wrap|Line Numbers
  1. File.Move(".\transfer\text.txt", ".\Desktop\AES file\transfer\text.txt");
  2.  
In a shell if you type "cd ." the character '.' is a reference to your current directory. If you type "cd .." the character '..' is a reference to your current directory's parent directory. You can use '.' and '..' anywhere you want. For example say I wanted to move text.txt to the C: root.
Expand|Select|Wrap|Line Numbers
  1. Move("C:\Documents and Settings\055949x\transfer\text.txt","..\..\..\text.text")
  2.  
Or say I wanted to move it to the My Pictures folder for the "All Users" account:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Move("C:\Documents and Settings\055949x\transfer\text.txt","..\..\All Users\Shared Documents\Shared Pictuers\text.text")
  3.  
Mar 30 '07 #4
walid
7 New Member
you have to use the move method. use the file system object FSO
Mar 30 '07 #5
walid
7 New Member
chech the following site.
http://builder.com.com/5100-6371_14-6089850.html
Mar 30 '07 #6
RedSon
5,000 Recognized Expert Expert
walid, you missed the point of the conversation. The OP asked "without having to write the full directory of the file". If you do not want to type out the full directory of the file you can use relative directory paths (ie '.' and '..')
Mar 30 '07 #7
fanoftvb
29 New Member
thanx for all the reply..i will try it out..^__^
Apr 2 '07 #8
fanoftvb
29 New Member
hi i currently has this code

strfile = Dir("*.txt")

If File.Exists(pat h) Then

File.Move("C:\D ocuments and Settings\055949 x\Desktop\AES file\" & strfile, "C:\Documen ts and Settings\055949 x\Desktop\AES file\transfer\" & strfile)
Label1.Text = ("File moved!")
Else
Label1.Text = ("File does not exist")
End If


i am using gridview and evey file has an id and a button next to it, when i click on the different buttons, the file whose button i click will move. But with the code above, i click on the same button and all the different files will move.. Is there any way to move the file according to the file ID...sry if my explaination is not clear..
Apr 2 '07 #9
pcpchandru
3 New Member
hi dear ,
please help me . am using vb.net windows application . how to open the .net solution file with in this application using vb.net code. if any of them knows please help send the code to me ..
Apr 2 '07 #10

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

Similar topics

15
3692
by: Mel | last post by:
if you know of dynamic expandable folder using CSS and display function, please drop me a note Yours, Mel
1
1939
by: Bryan Lynn | last post by:
Is there any way to store a GUID value as a property on a file/folder? When my app creates new files/folders, I'd like to store a GUID as a custom property on the file/folder. This way, when the user physically moves the file/folder using Windows Explorer (and not using my app), I can use this GUID to detect which files/folders were moved and my app can internally re-map some things. Any thoughts?
4
2691
by: Richard | last post by:
Hi all, Is there any class in .NET 1.x that will help me set file & folder permissions for a user? Aka - I would like to do the in code equivalent of right clicking a folder in file explorer and granting read/write access to a specific user {not the user running the program}. Any ideas? Or am I going to have to PInvoke like crazy??
0
982
by: Ajit | last post by:
Is there anyway to move attachments from a incoming email into a specified folder using System.Web.Mail ? has anyone done this ? Any help is appreciated.
2
5037
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
8
1918
by: Ajit | last post by:
Is there anyway to move attachments from a incoming email into a specified folder using System.Web.Mail ? has anyone done this ? Any help is appreciated.
2
2265
by: =?Utf-8?B?SmVmZnJleQ==?= | last post by:
I made a typo on a Project name (e.g. Wong, instead of Wang). Later on I renamed the Soution, Project, WebForm., etc, except the file folder name, back to Wang. Then after I closed the VS.net and went back to the Windows Explorer, I found out the file folder name was Wong, so I changed it to Wang. Next time, when I tried to open the Wang project, an error message showed that VS can not open the Wong Web page (something like that). ...
10
14284
by: kai | last post by:
Hi, All I am trying to create a file folder for any login user, and create sub folders for the user on a web page. After the user login again, he can only sees his own folder on the Web page. I am planning to use VB2005 or C#. I look the help files and searched on the web, I cannot find the answer. Is this possble in ASP.NET 2.0? Thanks
2
3332
by: anup wadekar | last post by:
I am able to access the exchange mail boxes of the mounted edb file using Active Directory Services such that i am retrieving the names of the user's and than setting the mail box to the user. CDO.Message objMsg; CDO.DropDirectory objDropDir = new CDO.DropDirectory(); CDO.IMessages objIMesgs; DirectoryEntry de = srUser.GetDirectoryEntry(); // Where srUser = "anup"
0
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5630
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.