Home All Groups Group Topic Archive Search About

Uploading and renameing image

Author
8 Sep 2006 5:56 PM
dfetrow410@hotmail.com
It will upload the first image, but if their is an image named the
same, it renames it and saves it, but when you look at the renamed
image, it is an x.


            ' Read file into a data stream
            Dim myData(nFileLen) As Byte
            myFile.InputStream.Read(myData, 0, nFileLen)
            ' Make sure a duplicate file doesn't exist.  If it does,
keep on appending an incremental numeric until it is unique
            sFilename = System.IO.Path.GetFileName(myFile.FileName)
            Dim file_append As Integer = 0

            While System.IO.File.Exists(Server.MapPath((sSavePath +
sFilename)))
                file_append = (file_append + 1)
                sFilename =
(System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) _
                            + (file_append.ToString + ".jpg"))
                sFilenameNoExt =
(System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) +
file_append.ToString)

            End While
            ImageFileName.Text = sFilename
            ' Save the stream to disk
            Dim newFile As System.IO.FileStream = New
System.IO.FileStream(Server.MapPath((sSavePath + sFilename)),
System.IO.FileMode.Create)
            newFile.Write(myData, 0, myData.Length)
            newFile.Close()

Author
10 Sep 2006 3:22 AM
Calvin Luttrell from Projecthunder
Does the file size = 0k?


Calvin Luttrell

How e-commerce is done.

http://blog.projectthunder.com
http://www.projectthunder.com


<dfetrow***@hotmail.com> wrote in message
Show quoteHide quote
news:1157738194.727683.245840@m79g2000cwm.googlegroups.com...
> It will upload the first image, but if their is an image named the
> same, it renames it and saves it, but when you look at the renamed
> image, it is an x.
>
>
>            ' Read file into a data stream
>            Dim myData(nFileLen) As Byte
>            myFile.InputStream.Read(myData, 0, nFileLen)
>            ' Make sure a duplicate file doesn't exist.  If it does,
> keep on appending an incremental numeric until it is unique
>            sFilename = System.IO.Path.GetFileName(myFile.FileName)
>            Dim file_append As Integer = 0
>
>            While System.IO.File.Exists(Server.MapPath((sSavePath +
> sFilename)))
>                file_append = (file_append + 1)
>                sFilename =
> (System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) _
>                            + (file_append.ToString + ".jpg"))
>                sFilenameNoExt =
> (System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) +
> file_append.ToString)
>
>            End While
>            ImageFileName.Text = sFilename
>            ' Save the stream to disk
>            Dim newFile As System.IO.FileStream = New
> System.IO.FileStream(Server.MapPath((sSavePath + sFilename)),
> System.IO.FileMode.Create)
>            newFile.Write(myData, 0, myData.Length)
>            newFile.Close()
>