Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
MY PROBLEM IS ima developing a windows application

iam doing converting image into text format and save into system location. this is my code

C#
if (!System.IO.Directory.Exists("D:\\SaveImageOutPutFolder")) 
{
    System.IO.Directory.CreateDirectory("D:\\SaveImageOutPutFolder");
    doc.Save(ConfigurationSettings.AppSettings["SaveImagefolderPath"] +@"\\MytxtFile.txt", Leadtools.Forms.DocumentWriters.DocumentFormat.Text, null); 
    MessageBox.Show("folder created and image output saved");         
}         
else  
{ 
    doc.Save(ConfigurationSettings.AppSettings["SaveImagefolderPath"] + @"\\MytxtFile.txt",    Leadtools.Forms.DocumentWriters.DocumentFormat.Text, null); 
    MessageBox.Show("ImageFolder is available  images are  Saved into folder Now");         
} 


problem is it is not create new txt file every time button click it is create the same file . iwant to create a new txt file for every click

any body help me in this and give an example code ....
Posted
Updated 17-Aug-11 20:37pm
v2

Hi You can also get the file count in the Directory and prepare a new name for your file.

C#
string[] strFileNames = Directory.GetFiles("D:\\SaveImageOutPutFolder\\" + ConfigurationManager.AppSettings["SaveImagefolderPath"], "MytxtFile*.*");


C#
string strNewFileName = "MytxtFile" + (strFileNames.Length + 1).ToString();
 
Share this answer
 
Use the following to create new file name
C#
string _newfilename=System.IO.Path.GetTempFileName();
 
Share this answer
 
You can add Time stamp to file name. This will help you to generate random files.

C#
string fileName="MyFile" + DateTime.Now.ToFileTime().ToString().Replace(" ","") + ".txt"; 
 
Share this answer
 
v4
It might be helpful,

C#
static string GenerateFilenameUsingGuid(string prefix, string extension)
{
     return string.Concat(prefix, Guid.NewGuid().ToString().Replace("-", string.Empty), extension);
}

static string GenerateFilenameUsingRandomNumber(string prefix, string extension)
{
     return string.Concat(prefix, new Random().Next(), extension);
}


:)
 
Share this answer
 
v2
Comments
Dalek Dave 18-Aug-11 4:09am    
Good Answer.
Mohammad A Rahman 18-Aug-11 4:10am    
Thanks Dalek :)
C#
string strFilename = "YourFile" + DateTime.Now.Ticks.ToString() + ".txt";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900