For Programmers: Free Programming Magazines  


Home > Archive > ASP > March 2008 > Rename a file which held in server using asp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Rename a file which held in server using asp
jain2005k@gmail.com

2008-03-04, 7:57 am

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

2008-03-04, 6:57 pm

<jain2005k@gmail.com> wrote in message
news:bcd9f3cd-a11c-44f1-a0b8-d47fd1371f64@d4g2000prg.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.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.


Sometimes MoveFile hasn't worked for me so I used CopyFile and
DeleteFile. You may want to test for FileExists between the two.


Brynn

2008-03-04, 9:57 pm

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.
jain2005k@gmail.com

2008-03-05, 3:56 am

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
jain2005k@gmail.com

2008-03-05, 3:56 am

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

Evertjan.

2008-03-05, 3:56 am

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)
jain2005k@gmail.com

2008-03-06, 3:57 am

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

2008-03-06, 3:57 am

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)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com