Solved

replace space in filename to underscore and save faile on hard disk using classic asp

Posted on 2010-09-01
3
840 Views
Last Modified: 2012-06-21
Hi , I have one page in which i have form to save the file in hard disk and database. everything is working fineexcept the file having space are causing the issue.

I have replce the space to undersore in the file name and successfully save in the database. File is also successfully saving in the hard disk. But on the hard disk, spaces are not replaced to underscore. I am using AspUpload .

Please see the files.
File1 having the form.
File2..
file1.doc
file2.doc
0
Comment
Question by:Saroj13
3 Comments
 

Author Comment

by:Saroj13
Comment Utility
I have this code. File is saved succeffully on the server. Problem is the space in the filename. I want to remove space from filename to underscore and then save tto the folder.

strUploadReadPath = "http://" & strUploadPath & "/CallTrack_Upload/UploadedFiles/"
      Set Upload = Server.CreateObject("Persits.Upload.1")

      Upload.OverwriteFiles = False
      On Error Resume Next

      Upload.SetMaxSize 1048576      ' Limit files to 1MB
      Count = Upload.Save("E:\Inetpub\wwwroot\CallTrack_Upload\UploadedFiles")
      
       For Each File in Upload.Files
       strUploadFileName = File.FileName
            
            'Response.Write strLogicalFileName & " : " & strUploadedFileName & "<br>"
      Next
      
      For Each Item in Upload.Form
            If Item.Name = "logicalfilename" Then
                  strLogicalFileName = Item.Value
            End If
            'Response.Write Item.Name &":" & Item.Value & "<br>"
      Next
      
      if Len(strLogicalFileName) > 0 and Len(strUploadFileName) > 0 then
            Response.Write strLogicalFileName & " : " & strUploadFileName & intCallId & ":" & strUploadReadPath
                  If InsertCallFileName( strLogicalFileName, strUploadFileName, strUploadReadPath, intCallId) then
                  end if
      end if

0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
Not familiar with AspUpload - I've been using this upload -
http://www.asp101.com/articles/jacob/scriptupload.asp

As for your issue here, it looks like you've been attempting to debug properly (many people don't seem to know how).  When you enable them, what do these lines display (I assume the file name - with or without the space?)

'Response.Write strLogicalFileName & " : " & strUploadedFileName & "<br>"
'Response.Write Item.Name &":" & Item.Value & "<br>"

Bottom line - the trick is to find out what variable is being used for the file name and using the replace command on it.

One thing you can try (if I'm reading the code correctly):
Change:
      For Each Item in Upload.Form
            If Item.Name = "logicalfilename" Then
                  strLogicalFileName = Item.Value
            End If
            'Response.Write Item.Name &":" & Item.Value & "<br>"
      Next

To:
      For Each Item in Upload.Form
            If Item.Name = "logicalfilename" Then
                  strLogicalFileName = Replace(Item.Value, " ", "_") 'Replace spaces with underscores
            End If
            'Response.Write Item.Name &":" & Item.Value & "<br>"
      Next
0
 
LVL 25

Accepted Solution

by:
kevp75 earned 500 total points
Comment Utility
You can use a loop to get the files you are trying to save, and instead of saving to a path, save the file.  On saving the file replace the spaces with an underscore

Set objFile = Upload.Form("File")
objFile.SaveAs Replace(objFile.Name, " ", "_")
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
X-Frame-Options - click-jacking 7 45
Classic ASP + JS 4 67
syntax error on ASP ? 6 39
asp syntax 3 20
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now