?
Solved

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

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

777 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