?
Solved

How would you modify the following IF statement to create 3 additional files with different file name extensions in a C# application on a Windows platform using VS2005?

Posted on 2012-09-08
2
Medium Priority
?
599 Views
Last Modified: 2012-09-09
I am working on developing a C# application on a Windows platform using VS2005.
How would you modify the following IF statement to create 3 additional files with different file name extensions, based on the value of the variable ExportedFile:

if (flename == "\\UDL.METRICS.PALLINT1.PALLINT1")
            {
                string iYear;
                DateTime time = DateTime.Now;
                string format = "yyyy";
                iYear = time.ToString(format);
                ExportedFile = MyProjectDir + flename + "." + iYear + "." + DateTime.Now.ToString("MMddhhmmss") + ".ARD.OUT.XLS";                
            }    

ExportedFile has a present value as follows:

\\UDL\OnDemand\PROD\UDL.METRICS.PALLINT1.PALLINT1.2012.0907165357.ARD.OUT.XLS

I would like to create 3 additional files names in which the file names start out the same as the variable ExporteFile but the file name endings are as follows:

\\UDL\OnDemand\PROD\UDL.METRICS.PALLINT1.PALLINT1.2012.0907165357.ARD

\\UDL\OnDemand\PROD\UDL.METRICS.PALLINT1.PALLINT1.2012.0907165357.ARD.IND

\\UDL\OnDemand\PROD\UDL.METRICS.PALLINT1.PALLINT1.2012.0907165357.ARD.OUT

The files would contain no data and the files can be assigned to variable names
strFile1, strFile2 and strFile3.
0
Comment
Question by:zimmer9
2 Comments
 
LVL 84

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 1600 total points
ID: 38380459
TempExportedFile = MyProjectDir + flename + "." + iYear + "." + DateTime.Now.ToString("MMddhhmmss")

ExportedFile = TempExportedFile +   ".ARD.OUT.XLS";
strFile1= TempExportedFile +   ".ARD";
strFile2= TempExportedFile +   ".ARD.IND";
strFile3= TempExportedFile +   ".ARD.OUT"
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 400 total points
ID: 38380498
A side comment. Instead of all this:
                string iYear;
                DateTime time = DateTime.Now;
                string format = "yyyy";
                iYear = time.ToString(format);
                ExportedFile = MyProjectDir + flename + "." + iYear + "." + DateTime.Now.ToString("MMddhhmmss")

You can simplify with a more .net-ish code:
                ExportedFile = string.Format("{0}{1}.{2:yyyy.MMddhhmmss}",  MyProjectDir, flename, DateTime.Now);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question