1

I have a folder "res/resx/" which contatins .resx files. What I want is to get all those .resx files.

Here is my code for that.

var Path = Server.MapPath("~/");
var SampleUrl = System.IO.Path.GetFullPath(System.IO.Path.Combine(Path, "Res/resx/"));
string[] files= System.IO.Directory.GetFiles(SampleUrl);
var AllFiles = new System.Collections.ObjectModel.ReadOnlyCollection<string>(files);
            foreach (string sFileName in AllFiles)
            {
                Response.write(sFileName + " <br>");
            }

This code is working on my local and i was able to see a list of my resx files. But when i deploy this to my website and access it, an error occurs on the 2nd line of code which says:

Could not find a part of the path 'D:\Websites\mywebsite.com\Res\resx'

I tried allowing directory browsing to see if my files exist. In my local, i can browse the files but on the website, I cannot. And it seems the system cannot find the folder "Res/Resx" too. it says:

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

But the folder exist and it is running on my local. Any advice as to what i should do or is their something i have missed? Thanks

  • Are you sure the folder actually exists on your webserver? Was it deployed together with the rest of the site? – Stephen Apr 05 '16 at 07:10
  • Yes the folder exist. I also tried transferring the .resx files to a folder in which the system can detect. and 'files' variable is not giving me any errors now. However. it cannot find any .resx files so the foreach loop doesnt execute. Is there some kind of configuration that the system does not let me read .resx files? – Voltaire John Secondes Biton Apr 05 '16 at 08:14

2 Answers2

0

Try this

string[] filePaths = Directory.GetFiles(Server.MapPath("Your folder"));
Nouman Bhatti
  • 1,341
  • 6
  • 28
  • 54
0

Look at the System.IO.Directory class and the static method GetFiles. It has an overload that accepts a path and a search pattern. Example:

string[] files = System.IO.Directory.GetFiles(path, "*.resx");

answered by Anthony Pegram here.

Community
  • 1
  • 1
habib ul haq
  • 824
  • 6
  • 13
  • It is working on my local PC but when i deploy it in my website, still giving error. I think the error is that it cannot find the .resx file. – Voltaire John Secondes Biton Apr 05 '16 at 07:16
  • check the permissions of the folder in your website, plus are you sure the folder is placed correctly? – habib ul haq Apr 05 '16 at 07:19
  • I actually dont know how to check the permission of the folder but i tried transferring the .resx files to a folder that the system of the website can read. And the directory.getfiles() function is working. However it does not detect .resx files so the AllFiles variable is empty so foreach loop wont execute. Maybe the system does not permit .resx to be read by default? – Voltaire John Secondes Biton Apr 05 '16 at 08:16