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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

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



<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:TextBox ID="txt1" runat="server" Visible="false" TextMode="MultiLine">asp:TextBox>



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)




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



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

if (ImageDir.Exists)


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



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

StreamWriter objectStreamWriter = default(StreamWriter);

objectStreamWriter = File.AppendText(FilePath);









Further Readings:

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

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