Solve my problem please.

Posted by Syedkhaja under Visual Studio on 10/16/2012 | Points: 10 | Views : 1032 | Status : [Member] | Replies : 2
I want to make application in C#.Net, after running that application i can save a file in particular today's date folder if it is in directory.
If today's date folder is not present in directory then application should create automatically today's date folder and save today working file in that folder.
Please help me soon..

Syed


Responses

Posted by: Rickeybglr on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
try this code ...in my case its working:

using System.Web.UI.WebControls;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.IO;
---
----
string folderName =DateTime.Today.ToString()
if (Directory.Exists(Server.MapPath("monthwiserecord\\ + folderName)))
{
// return;
}
else
{
Directory.CreateDirectory(Server.MapPath("monthwiserecord\\" + folderName));
string imzName = Path.GetFileName(FUImage.FileName); //file name
string path = Server.MapPath("monthwiserecord\\" + folderName + "/" + filename);
FUImage.SaveAs(path);
}

Syedkhaja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 10/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
try this code
  private static string applicationFolderName;

public static string ExecutingPath=AppDomain.CurrentDomain.BaseDirectory;

  private void button1_Click(object sender, EventArgs e)

{
string foldername = splitdate();
applicationFolderName = @"D:\" + foldername;
CreateApplicationFolder(applicationFolderName);
string str = splitfolderPath(ExecutingPath);
changesfile(str, applicationFolderName);
MessageBox.Show("Project Successed");

}
// Create Application Folder
private void CreateApplicationFolder(string str)
{
if (!Directory.Exists(str))
{
Directory.CreateDirectory(str);

}
}
private static string splitdate()
{
string date;
string format = "dd/MM/yyyy";
DateTime dt = DateTime.Now;
string[] str = dt.ToString(format).Split('/');
date = str[0] + str[1] + str[2];
return date;
}
private static string SplitedDate(DateTime dt)
{
string date;
string format = "dd/MM/yyyy";
string[] str = dt.ToString(format).Split('/');
date = str[0] + "\\" + str[1] + "\\" + str[2];
return date;
}

private void changesfile(string path,string designationPath)
{
string[] str = Directory.GetFiles(path);
foreach (string st in str)
{
string fileName = Path.GetFileName(st);
DateTime lastaccessTime = Directory.GetLastAccessTime(st);
string currentdate = SplitedDate(DateTime.Now); // "3/9/2008"
string accessdate =SplitedDate(lastaccessTime); // "3/9/2008"
if (currentdate == accessdate)
{
File.Copy(path + "\\" + fileName, designationPath + "\\" + fileName, true);
}
}
}
private static string fldPath;

private static string splitfolderPath(string str)
{

string[] Path = str.Split('\\');
foreach (string st in Path)
{
if (st != "bin")
{
fldPath += st + "\\";
}
else if (st == "bin")
{
break;
}

}
return fldPath;
}


It may be useful to you...


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Syedkhaja, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response