.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 >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Copy files from one folder to Another in ASP.NET

Posted By:Athira Sreejith       Posted Date: February 27, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

 

Copy files from one folder to Another in ASP.NET

 

.aspx:

<asp:RadioButtonList ID="rbtnDoc" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rbtnDoc_SelectedIndexChanged">

<asp:ListItem Value="D:\2008 Projects\Learn\Learn\Document\Modelpopup.txt">Modelpopupasp:ListItem>

<asp:ListItem Value="D:\2008 Projects\Learn\Learn\Document\Vetcare link.txt">Vetcare linkasp:ListItem>

<asp:ListItem Value="D:\2008 Projects\Learn\Learn\Document\SQLHelper.cs">SQLHelper.csasp:ListItem>

asp:RadioButtonList>

<asp:TextBox ID="txt1" runat="server" Visible="false" TextMode="MultiLine">asp:TextBox>

 

.cs:

using System.IO;

protected void rbtnDoc_SelectedIndexChanged(object sender, EventArgs e)

{

string filename = rbtnDoc.SelectedValue;

if (System.IO.Directory.Exists(Server.MapPath("Document")))

{

string[] arrFilename = filename.Split('\\');

int Count = arrFilename.Length;

string Fname = Path.GetFileName(arrFilename[Count - 1]);

FileInfo ObjFile = new FileInfo(Fname);

if (!ObjFile.Exists)

{

if (System.IO.Directory.Exists(Server.MapPath("NewFolder")) == false)

{

System.IO.Directory.CreateDirectory(Server.MapPath("NewFolder"));

}

FileInfo FileContent = new FileInfo(filename);

if ((FileContent.Exists))

{

StreamReader objectStreamReader = default(StreamReader);

string FilePath = filename;

objectStreamReader = File.OpenText(FilePath);

string contents = objectStreamReader.ReadToEnd();

txt1.Text = contents.ToString();

objectStreamReader.Close();

}

DirectoryInfo ImageDir = new DirectoryInfo(Server.MapPath("NewFolder"));

if (ImageDir.Exists)

{

FileStream fs = File.Create(Server.MapPath("NewFolder\\" + Fname));

fs.Close();

}

string FilePath = Server.MapPath("NewFolder\\" + Fname);

StreamWriter objectStreamWriter = default(StreamWriter);

objectStreamWriter = File.AppendText(FilePath);

objectStreamWriter.WriteLine(txt1.Text);

objectStreamWriter.Close();

}

}

}

 

 



     

Further Readings:

Responses
Author: nv         Company URL: http://www.dotnetspark.com
Posted Date: February 24, 2011

Sir
i am not able to configure your code

Plz help me with full file code

With regards

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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