.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to rename a file programmatically in c#

Posted By: priya     Posted Date: January 07, 2010    Points:2   Category :ASP.Net
Hi Friends,

How to rename a file programmatically in C# and asp.net? I want to modify the name and append the date in it using program dynamically.

Thanks in advance
priya

Responses
Author: Lalij Mer             
Posted Date: January 07, 2010     Points: 5   

Step 1:
Create a new website. Add a web.config file to your website (Right
Click project > Add New Item > Web Configuration File. Keep the
default name as Web.config and click Add).
Step 2: Make the following changes to your web.config

In your <system.web> tag, uncomment the <customError> tag. We will be reading and editing one of the attributes of this tag. The end result after removing the comments should be as shown below:

<authenticationmode="Windows" />

<!--

The <customErrors> section enables configuration

of what to do if/when an unhandled error occurs

during the execution of a request. Specifically,

it enables developers to configure html error pages

to be displayed in place of a error stack trace. -->



<customErrorsmode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

<errorstatusCode="403"redirect="NoAccess.htm" />

<errorstatusCode="404"redirect="FileNotFound.htm" />

</customErrors>



</system.web>


Step 3: We will now go ahead and make changes to the 'defaultRedirect' attribute of the <customErrors> tag, using the API we just discussed. For this purpose, add a textbox, label control and a button to the form. After adding the controls, the source view of Default.aspx would look similar to the following:

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="lblErrorPage" runat="server" Text="Rename Error Page to :"></asp:Label>

<asp:TextBox ID="txtError" runat="server"></asp:TextBox><br />

<br />

<asp:Button ID="btnRename" runat="server" Text="Rename" /></div>

</form>

</body>

</html>


The textbox will be used to display the default value of the 'defaultRedirect' attribute.

Step 4: In the Page_Load, display the current default value of the 'defaultRedirect' attribute. To do so, declare the objects for Configuration and WebConfigurationManager at form level and add the following code at Form_Load():

C#

Configuration configuration;

CustomErrorsSection section;



protected void Page_Load(object sender, EventArgs e)

{

configuration = WebConfigurationManager.OpenWebConfiguration("~");

section = (CustomErrorsSection)configuration.GetSection("system.web/customErrors");

txtError.Text = section.DefaultRedirect.ToString();

}

check this article
-------------------
http://www.dotnetcurry.com/ShowArticle.aspx?ID=102&AspxAutoDetectCookieSupport=1
http://forums.asp.net/p/1037680/2278719.aspx

Please Check my answer if you help....
Thank You...

Lalit.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend