Get a folder name that contains and string and then open it? - vb.net

This is the best i could do :
If fileName.Contains("hi")
But what i want to do it .
Open a folder : C:\Documents and Settings\5416339.5416339-PC\Application Data\ and navigate into a folder that contains "hi" and then modify a file pref.js in it. (100% this file is in that folder and there is only one such folder)
Can you guys do this for me ?
Thanks..

Look at the Directory and DirectoryInfo classes.
Both have methods that will list the contained directories and files - this should give you enough to find a directory called hi.
As for modifying the file, without knowing more about this file and how you want to modify it, I can't help.

Related

How to upload a file in Robot Framework?

I tried "choose file" but it is not working. I am not sure what to set 2nd argument to. I tried changing the different paths of file folder; it then navigates to the correct location but it's not selecting the text file or image in that location.
Choose File xpath ${path}
So I want to use AutoIt but I don't know how to combine it with Selenium, how to write code and where to keep the AutoIt script.
Here you need to give two arguments
Web-element locator of the Browse button or link where you want to upload the file (locators like id, name xpath, css are user)
then give the complete file path of the file you want to upload for Ex: If you file is in desktop and name of the file is fileName.txt then you path will be C:\Users\your_username\Desktop\fileName.txt (you can also use relative path of the file)
one such example line of code would be
1. Choose File ${xpath_locator} C:\Users\your_username\Desktop\fileName.txt
2. Chose File ${xpath_locator} ${file_path_variable}
where the ${file_path_varibale} taken from variable table of robot file.
you can explore more on all the Selenium Keywords in Robot Framework Here.
It's better way to get Project Path and join it with your specific upload folder. After that just put the location with file name :)
The easiest way is to write C: then image file ex. C:\image.jpg
Choose file xpath C:\yourImageofYourFile.jpg

Directory.GetDirectories on %USERPROFILE%\My Documents

I'm creating a UserControl for my program which will mimic the OpenFileDialog.
When I navigate to a Directory I am using
System.IO.Directory.GetDirectories(Path)
and
System.IO.Directory.GetFiles(Path)
to obtain the contents of the Directory.
When I navigate to %USERPROFILE% (In my case it is C:\Users*UserName*) and there is a hidden My Documents folder as well as a Documents folder.
When you navigate to the My Documents folder it takes you to the Documents folder, but it appears in the list from
System.IO.Directory.GetDirectories(Path)
My question is, is there a way, in code, to find where the My Documents folder is pointing to?
I know that I can find where the My Documents folder is by using
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
but I need to find the actual path each directory will save to in case it's different than it's actual address.
I'd be open to alternatives if it isn't possible.
Thanks

Open a specific file in vb.net

I want my program to open a specific .txt file. The text file will always stay in the same folder within the solution folder. However, the location of the solution folder itself may change if the solution is moved to a different computer, or a different directory on the current computer.
I know how to hardcode the file path append the file name and then open it. But how can I define the file path so that the file can still be opened if the solution moves to a different computer?
If the file is contained within the solution, you can use a virtual path which is then mapped to a physical path using Server.MapPath
The following should work :
Dim filePath As String = Server.MapPath("~/FileName.txt")
Please note that the location of FileName.txt in my example is in the root of the solution and not in any specified folders, ~/ is essentially the root of the current solution.
For more information on the Server.MapPath method and Virtual Paths see below:
Server.MapPath MSDN Documentation
Virtual Path Utility Class
If you are sure that your application (.exe) and (.txt) files are in the same folder, then just use the file name - do not put the path.
IO.File.OpenText("thefile.txt")
Edited:
Mostly "current working directory" is the same directory where the (.exe) file exists. Yes, sometimes, it is not the same directory. Thus, Application.ExecutablePath would be the right solution.
Dim fn As String
fn = Application.ExecutablePath.Remove(Application.ExecutablePath.LastIndexOf("\")+1) & "thefile.txt"
IO.File.OpenText("thefile.txt")
...
If you meant to say your FileName.txt was always present in the same directory as the assembly, you could do something simple like this:
Function GetAssemblyDirectoryPath() As String
Dim fullAssemblyPath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
Return fullAssemblyPath.Substring(0, fullAssemblyPath.LastIndexOf("\"c))
End Function
This just returns the path to the folder where the assembly resides. The "Solution" might not always be present, but the assembly will, so this will work in both cases (if you make sure the file is always copied to the output directory).
If you're asking about a desktop application, application.ExecutablePath will do what you want. It's not really a good idea though, if your application will reside within Program Files - it's best to avoid writing to anywhere within there, and you will have to run as administrator on post-XP OS's .

Vb. how to make the file save files in a folder iam using the files in form

Lets Says I Want To Make A Think Like Saver Forum But Another Think Like
Folder Browser Diadlog Download / Save Files I Use In The Forum Not Load Then Save
Files I Use It And In The Folder They Select (Another Pc) I Want It To Save The Files/Download In The Folder And They Will Be Think Named Wolfteam.exe Thats Mean Start The Game And Use The Files In The Game Folder
Thanks For Help.

How to get all files from a folder in sharepoint?

I am working on share point application. I want to get all files from a sub folder which is in a library.Library name is "Record Library". Inside this library folder name is "PROCUREMENT". Inside this folder i have one more folder name is "PURCHASING". In this folder i have file. I want to get all those file names. How can i get?
Please help me.
https://sharepoint.stackexchange.com/questions/19847/sharepoint-2010-how-to-get-all-items-in-a-folder-contained-in-a-list
This might help. People will not write the code for you. You need to attempt what you are asking.