Read Extension of file in resources - vb.net

How can I write a code to read the extension of a My.Resources file?
Example:
if i have a file named IMG.JPEG in my resources
How can I make msgbox to show the extension .JPEG ?
I can show the file name but without extension with this
For Each Fe In My.Resources.ResourceManager.GetResourceSet _
(System.Globalization.CultureInfo.CurrentCulture, False, True)
MsgBox(Fe.Key)
Next
any help would be greatly appreciated
EDIT:
I can get the extension of file but as .BYTE[] and pictures as .Bitmap with this code
GT = Path.GetExtension(My.Resources.ResourceManager.GetObject(Fe.Key).ToString)
MsgBox(GT)
How can i get the original extension?

If you have the filename you just need:
sExt = System.IO.Path.GetExtension(sFileName)
Or:
sExt = sFileName.SubString(sFileName.LastIndexOf("."c))

Related

Word VBA error 4199 File not found for existing file, called from OneDrive document

I have a macro to copy some styles from a reference dotx file in the Template folder into the file I am editing. It works well if the file is purely in my local drive, but I receive a File not found error, code 4199, if the file being edited sits (locally) in OneDrive (business). Here is the code; the not-found file is in variable tpl, which points to an existing and valid file. If I run the same macro on the same file, but this time the file sits purely in a local folder, then there is no error.
I looked for similar cases online, but this seems to be an obscure occurrence. Thanks for any help!
'--start
Sub GetStylesfromTemplate_zToCStyleforReports()
Dim i, max As Integer
Dim Hdgs(11 + 1) As String
Dim tpl As String 'Complete path to template file
'Number of styles
max = 2
'List of styles
Hdgs(1) = "TOC 1": Hdgs(2) = "TOC 2"
' Environmental var plus end of template path and file name
tpl = Environ("APPDATA") & "\Microsoft\Templates\Report-ToC-Style-Here.dotx"
For i = 1 To max
Application.OrganizerCopy _
source:=tpl, _
Destination:=ActiveDocument, Name:=Hdgs(i), Object:=wdOrganizerObjectStyles
Next
End Sub
' -- End

Downloading a file into Application path

so i am using this code to download file
Dim exePath As String = Application.ExecutablePath()
My.Computer.Network.DownloadFile(TextBox2.Text, exePath & "/img.png")
where textbox2 contains url to .png file but i get this error
Note that test.exe is on Desktop.
You can do it in this way
My.Computer.Network.DownloadFile(TextBox2.Text, Environment.CurrentDirectory & "/img.png");
Environment.CurrentDirectory Will give you the current working directory.
I hope this will work for you.

Get *only* file path of files without extension [vb.net]

I'm using a function to get the file paths in my executable path with the extension txt.
Dim FileEntries as string() = _
Directory.GetFiles(Path.GetDirectoryName(Application.ExecutablePath), "*txt"
But now i figures out that it would be better to use this files without the txt extension, despite the fact i can use notepad to change the lines anyway.
How do i use this function to get only the files without the extension?
If i use only "*" it gets all the files, apart from the extension. Thank you!
-EDIT-
I want to avoid any file that it's not suppose to be in the path. I want to gather only the files that have no extension, and therefore avoid any other file. If somehow a file is created there, with any extension, i want to avoid it.
You can use LINQ:
Dim nonTxtFiles =
From fn In Directory.EnumerateFiles(Path.GetDirectoryName(Application.ExecutablePath))
Where Not String.Equals(Path.GetExtension(fn), ".txt", Stringcomparison.InvariantCultureIgnoreCase)
Dim FileEntries as string() = nonTxtFiles.ToArray()
If you only want files without extensions(you have edited your question), it's easy:
Dim noExtFiles = From fn In Directory.EnumerateFiles(path)
Where String.IsNullOrEmpty(IO.Path.GetExtension(fn))
Another solution with Linq is to use the Path.GetExtension() method to see if the file has an extension:
Sub Main
Dim files = getFilenamesWithNoExtension("C:\SomeFolder")
End Sub
Private Function getFilenamesWithNoExtension(foldertosearch As String) As String()
Dim result As String()
result = Directory.EnumerateFiles(foldertosearch).Where(Function(f) String.IsNullOrEmpty(Path.GetExtension(f))).ToArray()
Return result
End Function

VB.NET - Check if URL is a directory or file

Is there a way, in VB.NET, to check if a URL is a directory? I've seen a lot of methods of checking if a local path is a directory but what about a remote url (i.e. http://website.com/foo) I read that some plain text files have no extension so I need a solution other than checking what if the file name contains a space or something.
You can use FileAttributes class:
'get the file attributes for file or directory
FileAttributes attr = File.GetAttributes("c:\\Temp")
'detect whether its a directory or file
If ((attr & FileAttributes.Directory) = FileAttributes.Directory) Then
MessageBox.Show("Its a directory")
Else
MessageBox.Show("Its a file")
End IF
Or you can use the Uri class:
Private IsLocalPath(Byval p As String) As Boolean
Return New Uri(p).IsFile
End Function
You can enhance this method to include support for certain invalid URIs:
Private IsLocalPath(Byval p As String) As Boolean
If (p.StartsWith("http:\\")) Then
Return False
End IF
Return New Uri(p).IsFile
End Function
The only solution I can think of is to try to download the file from the Internet, if the download succeeded So it is a file, otherwise it is not a file (but you don't know for sure that this is a directory).
This worked for me...
If System.IO.Path.HasExtension(FileAddress.Text) Then
MessageBox.Show("Its a file")
Else
MessageBox.Show("Its a directory")
End IF

Playing flash file in vb.net

I did some research and come up with this code.
AxShockwaveFlash1.Stop()
AxShockwaveFlash1.Movie = Application.StartupPath & "\RSAppt.swf"
AxShockwaveFlash1.Play()
playBtn.Enabled = False
I don't know why the video is not playing. My RSAppt.swf file is located at a resources(foldername) folder under my project. Is it the path? What is the right way to direct it to the specific path of my .swf file. Any ideas? Thanks!
This should work just fine.
Dim path As String = Application.Startuppath & "\yourfolder\yourfile.swf"
AxShockwaveFlash1.LoadMovie(0, path)
AxShockwaveFlash1.Play()
AxShockwaveFlash1.Loop = False
Happy Coding!!
You need to have:
AxShockwaveFlash1.Show()