Solved

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

Posted on 2010-09-01
3
849 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
ID: 33580424
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
ID: 33583973
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
ID: 33586189
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP - x-editable save to SQL 3 95
how to hide hide popup page refresh second time? 10 125
How to hide jquery hemiintro in returning user? 1 74
Button to go back 3 25
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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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