Rename a file which held in server using asp

J

jain2005k

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.MapPath("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.
 
B

Brynn

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.
 
J

jain2005k

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
 
J

jain2005k

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"));
 
E

Evertjan.

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.
 
J

jain2005k

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top