Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-01
3
Medium Priority
?
865 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 96

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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

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