By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,676 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,676 IT Pros & Developers. It's quick & easy.

Rename a file which held in server using asp

P: n/a
How can I rename a .jpg file in server using asp( not asp.net) code

I use the FileSystemObject to do that like
Fso = Server.CreateObject("Scripting.FileSystemObject");
Fso.MoveFile(Server.MapPath("1.jpg"),(Server.MapPa th("2.jpg"));
but it does not work properly
when I use the the code in my local system it also not worked.

But when I put full filepathpath instead of mapPath in my local
system. Like
Fso.MoveFile("c:\\inetpub\\1.jpg", "c:\\inetpub\\2.jpg")
It worked properly.

May anyone help me to do this with Server.MapPath() method.
Mar 4 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
<ja*******@gmail.comwrote in message
news:bc**********************************@d4g2000p rg.googlegroups.com...
How can I rename a .jpg file in server using asp( not asp.net) code

I use the FileSystemObject to do that like
Fso = Server.CreateObject("Scripting.FileSystemObject");
Fso.MoveFile(Server.MapPath("1.jpg"),(Server.MapPa th("2.jpg"));
but it does not work properly
when I use the the code in my local system it also not worked.

But when I put full filepathpath instead of mapPath in my local
system. Like
Fso.MoveFile("c:\\inetpub\\1.jpg", "c:\\inetpub\\2.jpg")
It worked properly.

May anyone help me to do this with Server.MapPath() method.
Sometimes MoveFile hasn't worked for me so I used CopyFile and
DeleteFile. You may want to test for FileExists between the two.
Mar 4 '08 #2

P: n/a
Just for testing sake ... try your Server.MapPath("/1.jpg") ... and
same with your 2.jpg

Whenever I use virtual paths, I like to start them from the root
directory. If nothing else, it will be a good way to test your code.
Being that I don't know where the file is that is running your asp.
You have to remember that the virtual path is going to start from the
calling asp file. So if your setup is like this ...
/1.jpg
/2.jpg
/folder/my.asp

Then that is why it isn't working ... because Server.MapPath ... or
anything using a virtual path is using it starting from the calling
asp page ... and just putting 1.jpg would make it think /folder/
1.jpg. To stop that ... always start your virtual paths from the root
directory ... that is all your paths from / being the root of your
website /1.jpg

Without knowing where your asp page this is just added info.
Another example ...

/images/1.jpg
/mycode/myfile.asp

would be Server.MapPath("/images/1.jpg"), Server.MapPath("/images/
2.jpg")

Even though in the code is in a different directory, you got to your
image paths by starting at the root and going forward.

Take care.
Mar 5 '08 #3

P: n/a
Brynn, thanks for your replay.
I change the code as per your suggestion. But it does not work.
I mention the full path
Fso.MoveFile("c:\\inetpub\\1.jpg", "c:\\inetpub\\2.jpg") is just for
example.
It is correctly Fso.MoveFile("c:\\inetpub\\wwwroot\\support\\1.jpg ", "
c:\\inetpub\\wwwroot\\support\\2.jpg");.
And the asp file is also in the same folder.( "c:\\inetpub\\wwwroot\
\support\\")
When I use the code as
Fso.MoveFile("c:\\inetpub\\wwwroot\\support\\1.jpg ", " c:\\inetpub\
\wwwroot\\support\\2.jpg").
In my local machine it works properly.
But when I use the same code as
Fso.moveFile(Server.MapPath("/support/2.jpg"), Server.MapPath("/
LiveSupport/3.jpg"));
It does not works and print an error

Error Type:
Microsoft JScript runtime (0x800A0046)
Permission denied
/support/Changename.asp.
Is it the problem of permission?. If yes , what can I do for allow
the permission.

Thanks jain
Mar 5 '08 #4

P: n/a
Brynn, there is a small mistake in my previous message
>But when I use the same code as
Fso.moveFile(Server.MapPath("/support/2.jpg"), Server.MapPath("/
LiveSupport/3.jpg"));
both folder are same
it is currectly
Fso.moveFile(Server.MapPath("/support/2.jpg"), Server.MapPath("/
support/3.jpg"));

Mar 5 '08 #5

P: n/a
wrote on 05 mrt 2008 in microsoft.public.inetserver.asp.general:
Brynn, thanks for your replay.
I change the code as per your suggestion. But it does not work.
I mention the full path
Fso.MoveFile("c:\\inetpub\\1.jpg", "c:\\inetpub\\2.jpg") is just for
example.
It is correctly Fso.MoveFile("c:\\inetpub\\wwwroot\\support\\1.jpg ", "
c:\\inetpub\\wwwroot\\support\\2.jpg");.
And the asp file is also in the same folder.( "c:\\inetpub\\wwwroot\
\support\\")
When I use the code as
Fso.MoveFile("c:\\inetpub\\wwwroot\\support\\1.jpg ", " c:\\inetpub\
\wwwroot\\support\\2.jpg").
This escaping the \ depends on your using ASP-JS or ASP-VBS.
In my local machine it works properly.
But when I use the same code as
Fso.moveFile(Server.MapPath("/support/2.jpg"), Server.MapPath("/
LiveSupport/3.jpg"));
It does not works and print an error

Error Type:
Microsoft JScript runtime (0x800A0046)
Permission denied
/support/Changename.asp.
Is it the problem of permission?. If yes , what can I do for allow
the permission.
This is as it should be. The ASP user should not have permission to access
the whole of the c: hd. In an of-web environment you could change te
permission, but that is outside the ASP Topic.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 5 '08 #6

P: n/a
Evertjan.
That is correct. Thanks. I change the permission of the
folder and allow modify permission to internet guest account in my
local system and it works properly. Then allow the same to the folder
in website and it also works properly.

jain
Mar 6 '08 #7

P: n/a
wrote on 06 mrt 2008 in microsoft.public.inetserver.asp.general:
Evertjan.
That is correct.
??

[please always quote on usenet]
Thanks. I change the permission of the
folder and allow modify permission to internet guest account in my
local system and it works properly. Then allow the same to the folder
in website and it also works properly.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 6 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.