.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 >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Directory Problem

Posted By: Naim Khan     Posted Date: January 06, 2009    Points:2   Category :Windows Application
Sir i have Created Folder With Directory. but my qus is that When i m created Next Folder my three Files Would be Copy to Other Folder which is created by me. i dont know how can i do this. and i m sending my Code. plz check it and reply me Fast sir

This is the Code to create Folder and Files.
try
{

con = new SqlConnection(Program.ConStr);
con.Open();
SqlCommand cmd = new SqlCommand("insert YearOfOperation(DefaultYear,AssessmentYear,FromYear,ToYear,TDSChI,TDSChD,BSRCode,Name,Designation,Address#1,Address#2,Address#3,City,PinCode,ChallanType,PrintChallan,EducationCess) values('" + txtDsetup.Text + "','" + txtAsse.Text + "','" + txtFto.Text + "','" + txtTo.Text + "','" + txtTDSIssued.Text + "','" + txtTDSDeposite.Text + "','" + txtBSR.Text + "','" + txtName.Text + "','" + txtDesn.Text + "','" + txtAdd1.Text + "','" + txtAdd2.Text + "','" + txtAdd3.Text + "','" + txtCity.Text + "','" + txtPin.Text + "','" + txtChallan.Text + "','" + comboBox2.Text + "','" + txtEcess.Text + "')", con);
cmd.ExecuteNonQuery();
string activeDir = @"D:\Contax DataBase";
string year = txtDsetup.Text;
string newPath = System.IO.Path.Combine(activeDir, year);
System.IO.Directory.CreateDirectory(newPath);
string newFileName = System.IO.Path.GetRandomFileName();
newPath = System.IO.Path.Combine(newPath, newFileName);
if (!System.IO.File.Exists(newPath))
{
using (FileStream fs = new FileStream(newPath, FileMode.CreateNew))
{
BinaryWriter bw = new BinaryWriter(fs);
string DefaultYear = txtDsetup.Text;
string AssessmentYear = txtAsse.Text;
string FromYear = txtFto.Text;
string ToYear = txtTo.Text;
string TDSChI = txtTDSIssued.Text;
string TDSChD = txtTDSDeposite.Text;
string BSRCode = txtBSR.Text;
string Name = txtName.Text;
string Designation = txtDesn.Text;
string Add1 = txtAdd1.Text;
string Add2 = txtAdd2.Text;
string add3 = txtAdd3.Text;
string City = txtCity.Text;
string PinCode = txtPin.Text;
string challanType = txtChallan.Text;
string PrintChallan = comboBox1.Text;
string EduCess = txtEcess.Text;
bw.Write(DefaultYear);
bw.Write(AssessmentYear);
bw.Write(TDSChI);
bw.Write(TDSChD);
bw.Write(BSRCode);
bw.Write(Name);
bw.Write(Designation);
bw.Write(Add1);
bw.Write(Add2);
bw.Write(add3);
bw.Write(City);
bw.Write(PinCode);
bw.Write(challanType);
bw.Write(PrintChallan);
bw.Flush();
bw.Close();

//DirectoryInfo d1 = new DirectoryInfo(activeDir);
//DirectoryInfo d2 = new DirectoryInfo(year);

//FileInfo[] f = d1.GetFiles();

//foreach (FileInfo f1 in f)
//{
// f1.CopyTo(str);
DialogResult dr = MessageBox.Show("ARE YOU SURE YOU WANT TO CREATE FINANCIAL YEAR ? ", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
if (dr == DialogResult.Yes)
{
this.Close();
}
}
}

}

catch (Exception exc)
{
MessageBox.Show(exc.Message + "Retry Again");
}

Responses
Author: Praveen             
Posted Date: January 06, 2009     Points: 5   

Hi,
just modify this lines of code like this

foreach (FileInfo f1 in f)
{

DialogResult dr = MessageBox.Show("ARE YOU SURE YOU WANT TO CREATE FINANCIAL YEAR ? ", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
if (dr == DialogResult.Yes)
{
f1.MoveTo(str); // Here str should hold the path of newly created directory
}
}

Hope this will halp you

Happy Coding!!!

Author: Vuyiswa Maseko             
Posted Date: January 07, 2009     Points: 5   

Do not Post one Question many times



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