Solved

ASP MVC 3 - Modify Directory location

Posted on 2016-08-24
4
30 Views
Last Modified: 2016-08-25
I have the code below and I need to add a directory called "maintenance" after the cID. I tried adding it in manually using '+ "\maintenance\"'  after the + cId but it went all squiggly line on me. I am new the ASP MVC (Razor) so any help would be greatly appreciated!

Thanks!

               {
                    var maintPath = System.Configuration.ConfigurationManager.AppSettings.Get("MaintenancePath");
                    if (System.IO.Directory.Exists(maintPath))
                    {
                        maintPath += "\\" + cId";
                        var files = System.IO.Directory.GetFiles(maintPath);
                        foreach (string file in files)
                        {
                            var fileInfo = new System.IO.FileInfo(file);

                            var maintFile = new Models.ContractorMaintenanceFile(cId, file);
                            if (maintFile.IsValid)
                                fileList.Add(maintFile);
                        }
                    }
                }

Open in new window

0
Comment
Question by:filtrationproducts
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Randy Peterson earned 500 total points
ID: 41769527
It's because the \ is a special character you would need to do + "\\maintenance\\" for it to take.
0
 
LVL 1

Author Comment

by:filtrationproducts
ID: 41770280
That worked. I had to add it in a couple spots but it eventually worked.

Thanks!
0
 
LVL 8

Expert Comment

by:Randy Peterson
ID: 41770444
Glad that was all you needed.  Just as an FYI if you place an @ in front of the variable it eliminates the special character.  So for example...

string directory = "c://myfolder//somethingelse//"; could be re-written like:

string directory = @"c:/myfolder/somethingelse/";

And those would yield the exact same results.  But with the @ in front, it makes it easier to look at.
1
 
LVL 1

Author Closing Comment

by:filtrationproducts
ID: 41770507
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

860 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