Get Physical Folder site is running under - vb.net

I am looking to get the folder that my website is running under. I have used many different methods within HttpContext.Current.Request but none of them were returning what I was looking for. I can easily get the value using substring but it doesn't look very clean and was wondering if there was a shorthand way of getting the folder.
For example when I use the code.
HttpContext.Current.Server.MapPath("~")
I get C:\ClientProjects\Dev\v10.3\src\MySite
I can use:
HttpContext.Current.Server.MapPath("~").Substring(HttpContext.Current.Server.MapPath("~").LastIndexOf("\") + 1)
But this seems really bloated way to get the folder I'm running under.

You will be able to get the directory name from a System.IO.DirectoryInfo object.
Dim info As New System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath("~"))
Dim name As String = info.Name ' name will have the value "MySite"

Related

Getting the name of a process in VB.NET

I've been looking around for how to find the name of a process object gotten using System.Diagnostics.Process.GetProcesses (for instance, for the process firefox, 'Firefox') , and haven't been able to find anything. I've tried using MainWindowTitle, but instead of returning 'Firefox' it returns the name of the current tab, as that's what Firefox names it's window. Is there any way to find the actual display name of a process?
For Each p As Process In Process.GetProcesses()
Debug.WriteLine(p.ProcessName)
Next
This might work, but is untested.
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.processname

Alfresco lucene search cannot find folder

I have a folder in document library of a site. I want to find all content of that folder. Running following lucene/alfresco-fts query in Node Browser returns No items found:
PATH:"/app:company_home/st:sites/cm:mysite/cm:documentLibrary/cm:MyFolder/*"
Which is wrong, as I have documents in that folder and running same query for different folder returns proper result. Another strange thing is that I cannot get this folder: following query also returns No items found:
PATH:"/app:company_home/st:sites/cm:mysite/cm:documentLibrary/cm:MyFolder"
Also if I get content of document library then MyFolder is skipped in the results and subfolder is returned:
PATH:"/app:company_home/st:sites/cm:mysite/cm:documentLibrary/*"
Name | Parent
--------------|---------------------
cm:MyFolder2 | /app:company_home/st:sites/cm:mysite/cm:documentLibrary
cm:MySubfolder| /app:company_home/st:sites/cm:mysite/cm:documentLibrary/cm:MyFolder
I have checked the aspects and properties of MyFolder and they are the same as MyFolder2. I do not have any custom behaviours/rules/etc.
How can I make first lucene query work and return content of MyFolder?
Try updating metadata on the folder so Solr re-indexes it. You could also get its db id and then tell solr to re-index it by db id. If it has over 1000 children, a FTS query may fail. - Known issue. Try using a txmd query.
I would suggest you to get the node ref of the folder from folder details page and search in node browser. There you can get the primary path. Please cross verify the path you use to search using lucene or use that primary path to search for the folder in lucene search.
Another possibility is that the locale property(sys:locale) of the folder(MyFolder) will be different from the locale of your browser. Please check whether the locale of MyFolder and the other folders for which result is shown, are same or not. If not that can also be a reason.

how to handle multiple uploads?

I'm writing a program that can upload files to multiple FTP servers.
There is a table, at the top row there are the sites, and at the far left column there are the files. through this table I define what should be uploaded to where.
the program is already working, but what i want to do now is to upload the files parallely on each site. so when i hit start each column will go through the rows on its own and upload the files to that site if the content of the specific cell says so. sites can be any number between 1 and 50. and all uploads should be in parallel. (one file at the time for each site)
what i am asking is what is the best way to handle such thing? i know i have to set up multiple uploaders, but what is confusing me is how to keep track what each site is doing. the only thing i can come up with is an array of arrays. where each position is for a site, and the array at that position defines what file is beeing uploaded and all the informations it needs for that. would that be a good solution?
thanks!
You can put your data into array then use for loop
use this code
$web = ['www.firstSite.com','www.secondSite.com']
$user = ['firstUser','secondUser']
$pass = ['firstPass','secondPass']
for($i=0;$i<sizeof($web);$i++)
{
$conn_id = ftp_connect($web[$i]);
$login_result = ftp_login($conn_id,$user[$i],$pass[$i]);
if (ftp_put($conn_id, $server_file, $local_file, FTP_BINARY))
{echo "Success";}
else {echo "Failed";}
}
You can make a custom class and use a List(Of SiteFiles) for a collection of them. You iterate the sites data and create a new SiteFiles object for each site and add the files names to the Files property that need to be uploaded to that site. Then when your done making this List(Of SiteFiles) then you can iterate each file in SiteFiles.Files for each SiteFiles object and use threading/async methods if needed and upload the files. This gives you a neat and tidy way to organize what your doing.
Public Class SiteFiles
Public Property Site As String
Public Property Files As New List(Of String)
End Class

How to set "always open by this program"

i want my program to ask user "Do u want to set .mp3 file type always default open by this program?" (for first time only) any example to do this?
First, you will need to familiarize yourself with the Windows Registry.
Associations between programs and extensions are handled inside the HKEY_CLASSES_ROOT key.
Each extension appears as a sub-key.
As each key's default value you will find the associated key that handles most of the operations, currently supported, for that particular file type.
For example, you might find the .mp3's default value is set to "WMP11.AssocFile.MP3" or perhaps it set to "VLC.mp3", if you have installed VLC and configured it as the default MP3 player.
So, now you need to locate that key, again, inside HKEY_CLASSES_ROOT.
Although this may vary, you should find that "VLC.mp3" (or whatever key was associated with the .mp3 extension) has a sub-key called "shell".
Under "shell" you will find another sub-key called "Open".
And, finally, under "Open" you will another sub-key called "Command".
The "Command" key is the one containing the information used by Windows (and other programs) to open/start whatever application is currently associated with the ".mp3" (or any other) extension.
Once you understand and feel comfortable with the way associations are handled in the Registry, you should then use .NET's Microsoft.Win32's Registry class to navigate and query the required keys and their values.
Here's a very basic illustration of how the code would look like:
Dim mp3 = Registry.ClassesRoot.OpenSubKey(".mp3")
Dim associatedValue = mp3.GetValue("")
Dim associatedKey = Registry.ClassesRoot.OpenSubKey(associatedValue)
Dim defaultProgram = associatedKey.OpenSubKey("Shell\Open\Command").GetValue("")
MsgBox("MP3 Files Are Opened Using: " + vbCrLf + defaultProgram)
Hope this helps...
You need to set file associations. See this article on Code Project on setting File Associations in VB.NET.
An error shows up again after importing and declaring it like
Dim rgText As Registry.ClassesRoot.OpenSubKey(".txt")
and the error looks like this:
Type 'Registry.ClassesRoot.OpenSubKey' is not defined.

Delete Folders and Containing Files

I have a really quick question. My program actually downloads a zip file then extracts it onto their desktop. But I need an uninstall feature for it, which is basically deleting multiple folders and containing files. How can I do this in vb.net?
If all of your folders are contained in a single folder, it should be pretty straight forward.
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YOURPATH"
System.IO.Directory.Delete(path, True)
That will delete your root directory, and all the directories and files below it. You could just call this several times over if your files and directories are not all in a single root directory like "YOURPATH" in the example. This will spare you from having to remove each file individually.
The .NET IO unit has a two commands that should let you do the trick:
System.IO.Directory.GetDirectories("C:\\Program Files\\Your Directory\\*.*");
System.IO.Directory.GetFiles("C:\\Program Files\\Your Directory\\*.*");
I would write a method that takes the name of a directory and uses the "GetFiles" routine to get all of the files and to delete them using System.IO.File.Delete(path) in a foreach loop. Then, run a foreach loop on the result of the GetDirectories() command calling the function recursively.
Update: Steve Danner points out that the System.IO.Directory namespace has a Delete method so you don't need to go through the loops I talk about here. His answer is the right one and should be voted up. Mine, at this point, is more of a curiosity (although thank you to the person who gave me an upvote ;0).
Your are looking for DirectoryInfo, use it like this:
Dim di As New IO.DirectoryInfo(path)
di.Delete(True)
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YOURPATH"
System.IO.Directory.Delete(path, True)