Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2005, 09:44 AM
Authorized User
 
Join Date: May 2005
Location: Stafford, , United Kingdom.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default File extension detection

I'm uploading a file and want to detect its file extension, so I can add it onto the path of the file, for example 435.jpg, in classic asp I used - File.ext

How do you detect it in ASP.Net (VB)?


Also, how do you overwrite files? Here is my sub


Sub Upload_Click(Sender as Object, e as EventArgs)

      UploadDetails.visible = True

' Let us recover only the file name from its fully qualified path at client

        Dim strFileName as string
        strFileName = MyFile.PostedFile.FileName
        Dim c as string = System.IO.Path.GetFileName(strFileName) ' only the attched file name not its path

                 ' Let us Save uploaded file to server at C:\ServerFolder

  Dim strSQL2 As String = "UPDATE Product set Prod_Image = " & _
                          " '" & c & "' WHERE ProdID = " & Request("ProdID")


  Connect()

  Dim dbComm As New SqlCommand(strSQL2, objConnection)
  dbComm.ExecuteNonQuery()
  Disconnect()

           MyFile.PostedFile.SaveAs(getAssetsPath + c)
     UploadDetails.Overwrite = True


              Response.Redirect("products.aspx?ProdRangeID=" & Request("ProdRangeID"))

End Sub
 
Old October 31st, 2005, 04:03 AM
Authorized User
 
Join Date: Jul 2005
Location: Chennai, Tamil Nadu, India.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Path.GetExtension(strFilePath)

would get you the File Extension. Path class is available in System.IO namespace.

Vasudevan Deepak Kumar
Personal Web: http://www.lavanyadeepak.tk/
I Blog At: http://deepak.blogdrive.com/
 
Old November 2nd, 2005, 11:46 AM
Authorized User
 
Join Date: May 2005
Location: Stafford, , United Kingdom.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, works fine





Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUpload control -- file size detection ekwong ASP.NET 2.0 Basics 3 November 7th, 2006 06:32 PM
how to open a pagemaker file with the extension .p yogeshwari_am Visual C++ 0 November 2nd, 2006 07:32 AM
.att file extension??? joffy Intro Programming 1 July 24th, 2006 01:33 AM
retrive file extension Dj Kat Javascript How-To 2 December 10th, 2005 01:35 PM
What file extension should I use? pigtail Javascript 3 April 12th, 2004 02:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.