I want to read the file extension when uploading a file. How can i read the file extension and allow only certain types of files to be uploaded?
Can anyone help please?
CODE
==============
If
(Me.fileUpload_fu.PostedFile <>
Nothing) Then
Dim contentLength As
Integer = Me.fileUpload_fu.PostedFile.ContentLength
If (contentLength > 0)
Then
errorMsg = ""
Dim originalFileName
As String = System.IO.Path.GetFileName(Me.fileUpload_fu.PostedFile.FileName)
Dim fileExtension
As String = ?????
Dim tempFileName
As String = originalFileName
Dim SaveLocation
As String = tempWebServerSaveLocation & "\" & fn
Me.fileUpload_fu.PostedFile.SaveAs(SaveLocation)
Return
True
Else
Dim fileExtension As String = _
Me.fileUpload_fu.PostedFile.FileName.SubString( _
Me.fileUpload_fu.PostedFile.FileName.LastIndexOf("."))
' returns strings like ".jpg"
(I understand that much time has passed since you posted your question, but I would like to add my comment for any future people that stumble across your post when searching the web.)
An easier solution would be to use something similar to what you already used:
Dim fileExtension As String = System.IO.Path.GetExtension(Me.fileUpload_fu.PostedFile.FileName)
imran buchh
Participant
1160 Points
265 Posts
Read File Extension
Aug 21, 2006 11:48 PM|LINK
Hello,
I want to read the file extension when uploading a file. How can i read the file extension and allow only certain types of files to be uploaded?
Can anyone help please?
CODE
==============
If
(Me.fileUpload_fu.PostedFile <> Nothing) ThenDim contentLength As Integer = Me.fileUpload_fu.PostedFile.ContentLength If (contentLength > 0) Then
errorMsg = ""
Dim originalFileName As String = System.IO.Path.GetFileName(Me.fileUpload_fu.PostedFile.FileName) Dim fileExtension As String = ????? Dim tempFileName As String = originalFileName Dim SaveLocation As String = tempWebServerSaveLocation & "\" & fn Me.fileUpload_fu.PostedFile.SaveAs(SaveLocation) Return True ElseerrorMsg = "Please select a valid file"
Return False End If ElseerrorMsg = "Please select a valid file"
Return False End If=============
Cheers,
Imran
http://www.uandisolutions.com
Ryoushin
Member
292 Points
81 Posts
Re: Read File Extension
Aug 22, 2006 11:46 AM|LINK
Dim fileExtension As String = _ Me.fileUpload_fu.PostedFile.FileName.SubString( _ Me.fileUpload_fu.PostedFile.FileName.LastIndexOf(".")) ' returns strings like ".jpg"omueller
Member
2 Points
1 Post
Re: Read File Extension
Feb 20, 2008 11:03 PM|LINK
(I understand that much time has passed since you posted your question, but I would like to add my comment for any future people that stumble across your post when searching the web.)
An easier solution would be to use something similar to what you already used: