Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Replace() help
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

weeweeslap
Senior Member

USA
1077 Posts

Posted - 05 September 2007 :  23:18:10  Show Profile  Visit weeweeslap's Homepage  Send weeweeslap an AOL message  Send weeweeslap a Yahoo! Message
Hi,
I am trying that when on upload, any file that has a space in it's name gets the space removed thus the file ends up all one big word, right, liek example say the file name is "hello world.txt" I want it to be shurnk down to "helloworld.txt" I tried:
strFile = Replace(strNewFile, " ", "")
As you can se in the code below, I tried placing it in various places, either before the file is saved upl.save or after it and I've had no luck. When the upload is finished it gives me the file name and says it has been saved as I've wanted to save it, that is without filename spaces, but it gets uploaded with the spaces that the user origianlly uploaded the file with. I was hoping you guys can point me where to properly move my code or the proper code to use for this action that I want. Thank you, the code in question is below.

if Request.QueryString("uploader") = "true" then
   Set upl = Server.CreateObject("SoftArtisans.FileUp") ' Creating upl object!
   basePath  = Server.MapPath(".") ' mapping the default path where files will be stored on the hard disk!
   upl.Path = basePath & "\"

       if not upl.IsEmpty Then 'we check if the object is empty or has a null value!
           'on error resume next
           strNewFile = upl.UserFilename 'Storing name of the file in a temporary variable!
           strFile = Replace(strNewFile, " ", "_")
           upl.Save 'Saving the uploaded file
strFile = lcase(Mid(strFile, InstrRev(strFile, "\") + 1))
strFormTrackFileExtension = lcase(Mid(strFile, InstrRev(strFile, ".")))
If strFormTrackFileExtension=".jpg" Then
Else
Response.Write "<html><head><title>WeeWeeSlap.com Scrapbook</title></head><body bgcolor=""#131313""><font color=""#FFFFFF""><li>Invalid file, it must be .jpg only.</li><br><a href=""javascript:history.go(-1)"">Go back and try a different file to upload</a></font></body></html>" & vbCrLf
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
strFile = "###########" & strFile
ScriptObject.DeleteFile(strFile)
Response.End
End If
           strFileTemp = strFile
           aryFileName = Split(strFile,"\")
           lastVal = UBound(aryFileName) 'Checking the Ubound after spliting the file name!
           strFile = aryFileName(lastVal)
           strFileTemp = strFile    'actual file name with its type stored in a variable!
       end If
end if
%>

coaster crazy

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 06 September 2007 :  12:49:50  Show Profile  Send pdrg a Yahoo! Message
Just a sidenote, but the replace will (I believe) need to be looped, or it'll just remove the first space
Go to Top of Page

RArch
Junior Member

United Kingdom
103 Posts

Posted - 06 September 2007 :  13:01:50  Show Profile
The folowing line in your code replaces spaces with an underscore.

strFile = Replace(strNewFile, " ", "_")

You should change that line.
Go to Top of Page

weeweeslap
Senior Member

USA
1077 Posts

Posted - 06 September 2007 :  13:10:53  Show Profile  Visit weeweeslap's Homepage  Send weeweeslap an AOL message  Send weeweeslap a Yahoo! Message
yeah I aware of that, I tested the underscore to see if it would add that instead of removing the space but it did not. Not sure why the code isn't working when saving the file.

coaster crazy
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 06 September 2007 :  13:41:53  Show Profile  Visit HuwR's Homepage
you probably need to use a SaveAs method rather than just doing a Save
Go to Top of Page

weeweeslap
Senior Member

USA
1077 Posts

Posted - 06 September 2007 :  15:34:49  Show Profile  Visit weeweeslap's Homepage  Send weeweeslap an AOL message  Send weeweeslap a Yahoo! Message
you are correct,I tried the up.SaeAs method and it isn't working either, something wrng, I need a different approach perhaps, my members already abused of the new feature I am working on, really ticks me off when they can't apreciate the work one does for them. Thanks guys for your help!

coaster crazy
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 1.77 seconds. Powered By: Snitz Forums 2000 Version 3.4.07