I have a requirement to swap two three .aspx files based on user action.
For Example: -
Under root i have subfolder say "helper" within this I have two .aspx pages "original_page.aspx", "dummy_page.aspx"; In Root we have file "original_page.aspx" at the same time we have another landing page where user action takes place now on user clicks
we have to copy "helper\dummy_page.aspx" and paste in the root folder as "original_page.aspx" with replace. When suer clicks another button we have to copy "helper\original_page.aspx" and paste in the root folder as "original_page.aspx" with replace.
Why do you want to overwrite the file? If the intention is to use the file after overwriting, then you can redirect the user to the page that you're overlaying. If my understanding of your requirement is incorrect, can you provide more details on what you're
trying to achieve?
Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
Thanks for your time. Let me explain you reason behind replacing. The file "original_page.aspx" in root folder will be calling by External System. When external system called it returns response message. Our requirement is to manipulate response message.
Here we cannot modify source "original_page.aspx" file.
santa_1975
Hi
Why do you want to overwrite the file? If the intention is to use the file after overwriting, then you can redirect the user to the page that you're overlaying. If my understanding of your requirement is incorrect, can you provide more details on what you're
trying to achieve?
Encourage me by Mark as "ANSWER" if above code really help full. Don't forgot to "Report Abuse" in case violates Terms and Conditions
Try HTTPModule if you would like to modify the content of the response dynamically. Refer to the below links for more information and step-by-step approach to develop a HTTPModule.
Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
I dont want to modify original_page.aspx page. Here we have to replace .aspx page at run time problem is IIS user dont have write permission to manipulate the page in same website. Any idea or suggestions to achieve this.
santa_1975
Hi,
Try HTTPModule if you would like to modify the content of the response dynamically. Refer to the below links for more information and step-by-step approach to develop a HTTPModule.
The file "original_page.aspx" in root folder will be calling by External System. When external system called it returns response message. Our requirement is to manipulate response message
Web Services are meant for such situation, where we need input from external sources or any kind of I/O with third-party vendors.
http://simpledotnetsolutions.wordpress.com/
2011 Microsoft Community Contributor Award Recipient
private void AttachServer()
{
File.Move(Server.MapPath("~/helper/original_page.aspx"), Server.MapPath("~/original_page.aspx"));
// This move file function does not rename files, only moves them from one location to another one
}
Best Regards
Primillo
http://www.facebook.com/programandopuntonet
1Madhu
Member
317 Points
119 Posts
Swapping two aspx page's at runtime
Jul 29, 2012 04:16 AM|LINK
Hi All,
I have a requirement to swap two three .aspx files based on user action.
For Example: -
Under root i have subfolder say "helper" within this I have two .aspx pages "original_page.aspx", "dummy_page.aspx"; In Root we have file "original_page.aspx" at the same time we have another landing page where user action takes place now on user clicks we have to copy "helper\dummy_page.aspx" and paste in the root folder as "original_page.aspx" with replace. When suer clicks another button we have to copy "helper\original_page.aspx" and paste in the root folder as "original_page.aspx" with replace.
I tried this but showing error
private void AttachServer()
{
File.Move(@"F:\webPage\helper\dummy_page.aspx", @"F:\webPage\original_page.aspx");
}
Throwing "Unable to copy file, Access to the path is denied"
Any help?
Regards,
Madhu,India
Primillo
Star
8723 Points
1677 Posts
Re: Swapping two aspx page's at runtime
Jul 29, 2012 04:50 AM|LINK
You only can access files in your root, and use Server.MapPath
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
Primillo
http://www.facebook.com/programandopuntonet
santa_1975
Star
8574 Points
1499 Posts
Re: Swapping two aspx page's at runtime
Jul 29, 2012 05:06 AM|LINK
Hi
Why do you want to overwrite the file? If the intention is to use the file after overwriting, then you can redirect the user to the page that you're overlaying. If my understanding of your requirement is incorrect, can you provide more details on what you're trying to achieve?
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
1Madhu
Member
317 Points
119 Posts
Re: Swapping two aspx page's at runtime
Jul 29, 2012 05:08 AM|LINK
Thanks for your reply.
Here path is correct even though i tried using server.MapPath still getting same error.
Regards,
Madhu,India
1Madhu
Member
317 Points
119 Posts
Re: Swapping two aspx page's at runtime
Jul 29, 2012 05:22 AM|LINK
Hi Santa_1975,
Thanks for your time. Let me explain you reason behind replacing. The file "original_page.aspx" in root folder will be calling by External System. When external system called it returns response message. Our requirement is to manipulate response message. Here we cannot modify source "original_page.aspx" file.
Regards,
Madhu,India
santa_1975
Star
8574 Points
1499 Posts
Re: Swapping two aspx page's at runtime
Jul 29, 2012 05:53 AM|LINK
Hi,
Try HTTPModule if you would like to modify the content of the response dynamically. Refer to the below links for more information and step-by-step approach to develop a HTTPModule.
http://msdn.microsoft.com/en-us/library/bb398986.aspx
http://support.microsoft.com/kb/307996
Hope this helps.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
1Madhu
Member
317 Points
119 Posts
Re: Swapping two aspx page's at runtime
Jul 29, 2012 06:15 AM|LINK
I dont want to modify original_page.aspx page. Here we have to replace .aspx page at run time problem is IIS user dont have write permission to manipulate the page in same website. Any idea or suggestions to achieve this.
Regards,
Madhu,India
DotNetSeeker
Contributor
3169 Points
589 Posts
Re: Swapping two aspx page's at runtime
Jul 30, 2012 02:49 AM|LINK
Web Services are meant for such situation, where we need input from external sources or any kind of I/O with third-party vendors.
2011 Microsoft Community Contributor Award Recipient
Primillo
Star
8723 Points
1677 Posts
Re: Swapping two aspx page's at runtime
Jul 30, 2012 03:27 AM|LINK
You can't use the full path for "File.Move" in asp.net app, you need to use Server.MapPath
You don't need to specify the full path with Server.MapPath
Server.MapPath("~/helper/original_page.aspx")http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
The Function File.Move, moves the file from here to there.
http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx
private void AttachServer() { File.Move(Server.MapPath("~/helper/original_page.aspx"), Server.MapPath("~/original_page.aspx")); // This move file function does not rename files, only moves them from one location to another one }Primillo
http://www.facebook.com/programandopuntonet
1Madhu
Member
317 Points
119 Posts
Re: Swapping two aspx page's at runtime
Aug 04, 2012 03:05 AM|LINK
Hi All,
My problem solved. I have given write permission to IIS_WPG user for "helper" folder.
Thanks Santa_1975, Primillo & dotNetSeeker for your time.
Regards,
Madhu,India