?
Solved

fileupload

Posted on 2008-06-26
6
Medium Priority
?
369 Views
Last Modified: 2013-11-26
I like to make changes to my code, Instead of uploading the file with the file name
of the file. I want to change it to upload the file to whatever name I want

Dim FileName As String
        Dim i As Integer
        Dim StoreID As String = ReadCookie(Tokens.StoreId)
        Dim StoreDir As String = CheckStoreDirectoryExists()
        Dim uploads As HttpFileCollection = HttpContext.Current.Request.Files
 
        NewTempDir()
 
        For i = 0 To uploads.Count - 1
            Dim FileToUpload As HttpPostedFile = uploads(i)
            '/*********************************/
            ' Error Handling here error
            '/*********************************/
            If (FileToUpload.ContentLength = 0) Then
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelGreen"
                    .Text = "Sorry there is no Excel File to Upload please try again."
 
                End With
 
            Else
                FileName = System.IO.Path.GetFileName(FileToUpload.FileName)
                Try
                    FileToUpload.SaveAs(StoreDir & "\" + FileName)
                Catch ex As Exception
                    With lblMessage
                        lblMessage.Visible = True
                        .CssClass = "labelGreen"
                        .Text = "Sorry there is no Excel File to Upload please try again."
 
                    End With
                End Try
            End If
        Next i

Open in new window

0
Comment
Question by:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 10

Assisted Solution

by:Dxpert
Dxpert earned 1500 total points
ID: 21878312

'you wouldn't need this line:
FileName = System.IO.Path.GetFileName(FileToUpload.FileName)

'you could change it to the new file name with the correct extension:
FileName = "NewFileName.TXT"

'the rest would be the same
      Try
            FileToUpload.SaveAs(StoreDir & "\" + FileName)
0
 
LVL 10

Assisted Solution

by:Dxpert
Dxpert earned 1500 total points
ID: 21878329
See the FileToUpload control already has the file. You use the "SaveAs" to specify a new file name. I think that's all you have to do.
0
 
LVL 10

Accepted Solution

by:
Dxpert earned 1500 total points
ID: 21878339
I meant FileUpload control.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 9

Author Comment

by:Seven price
ID: 21878368
Actually I figured it out below
But thanks Guys
 Dim FileInfo = "Excel.xls"
 
  FileToUpload.SaveAs(StoreDir & "\" + FileInfo)

Open in new window

0
 
LVL 10

Expert Comment

by:Dxpert
ID: 21878412
Just a tip ;-) Usually B grades are given when the expert doesn't write code and just refer to links, or writes incomplete code. If the answer was right on, then the grade should be A. Thanks!
0
 
LVL 9

Author Comment

by:Seven price
ID: 21879856
Sorry I will know better next time
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question