Solved

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

Posted on 2010-09-01
3
857 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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/…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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