I am working with Directory.GetFiles in C#. This code is turned into an assembly which is then used in a T-SQL script. Here is the code line that I believe is the problem:
C# Code:
string[] filePaths = Directory.GetFiles(path, ext, SearchOption.AllDirectories);
Error (T-SQL script):
System.IO.DirectoryNotFoundException: Could not find a part of the path 'G:\Photography\Archive\SPBKF3~L'.
I'm assuming the tilde isn't a legal character to use for a folder name in Windows because the only folders that cause this error are the ones with a tilde. The files are being shared between Mac and Windows systems and I've found that file and folder names have been a problem in the past.
I'm having a difficult time understanding why the Directory.GetFiles method would even find a directory that doesn't exist. The folder displays in Windows Explorer but I cannot access the folder.
Is there something I can do to avoid these problem folders?
SPBKF3~L looks suspiciously like an 8.3 shortened filename. Are you sure this isn't happening somewhere?
~ is not an invalid character - I just tried creating a directory with the name SPBKF3~L, and I also wrote up a quick C# app to run your sample code on that directory and it worked fine.
There must be something else happening here - are you absolutely sure that the directory exists? (try copying and pasting the path into an explorer window)
Check the permissions on G:\Photography\Archive\SPBKF3~L and ensure that the user account the SQL Server instance is running under can see the folder.
Related
I Ran FileInfo.MoveTo("filename.txt") with just a name instead of passing a full path and the file just disappeared. I believe in linux this would make it go to the root directory "/", but on Windows I'm not sure if there is a such thing as a root directory beyond just C: Is there any way to locate my lost file?
It is likely in the working folder that your executable is running from. For example, MyApp\bin\Debug, depending on the configuration you are running in.
It should be in project folder. Usually files without specefying path are saved there. (in folder with .exe file)
I made a python executable using pyinstaller. The executable requires a dataset folder, which I have given it in same directory, and as for output it makes a txt file. All this works good alone.
I decided to use VS to create a front end and used Process.Start(), I put the required files in same directory of final exe (Bin/debug folder) and as well as in "Solution Explorer", but I'm getting an "System cannot find file specified error". I also tried to use Process.Start(#Application.StartupPath+"\naivebayes.exe")
but getting same error.
I want to make a front end with buttons and each button to call a separate exe file and publish all the files together in a single project, what am I going wrong?
The first \ in your specified path tells the runtime too look for your naivebayes.exe in the root directory of the drive (which I assume wasn't your goal).
You should specify your filename without a leading \ (or use a leading dot even before it, since .\ construct would point relatively).
I'm basically creating a directory in MyDocuments. I think it's worth mentioning that MyDocuments at my company is a network path.
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
path = Path.Combine(path, string.Format(#"A\XXX\C\{0:yyyyMMdd_HHmmss}", startTime));
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
The issue here is quite funny. It was working fine for 2 years and recently I cleaned manually path in subdirectory 'XXX'. Now it doesn't work. If I change 'XXX' to anything else it works. It looks like something is wrong with this particular directory. I can delete that directory manually and recreate it in windows explorer. It happens when running from VS2015 and from exec as well. Any ideas?
Edit:
Just to clarify:
Exception thrown: "Could not find a part of the path"
In Line Directory.CreateDirectory(path);
Edit:
The reproduce in windows explorer:
I can create and remove XXX and C this is fine. When I tried to create any subdirectory in C windows explorer hangs. So I removed the entire A directory and now when I try to create it manually I can't recreate A because it says that the folder or a file in it is open in another program. How is it possible if it doesn't exist.
The answer is pretty simple. In your company we use sync center to synchronize data on this shared drive. The root directory wasn't fully synchronized so whenever I tried to create directory it thrown an error. After synchronizing and deleting it from my mirrored version and sync center version I could create it again.
I am using Visual Studio 2010 with Crystal Report. It is working fine in my local server but on web server, it is giving error :
System.Runtime.InteropServices.COMException: Invalid file name.
I tried many solutions like put .rpt file in any folder and provide that path, give full permission to windows temp folder, enable parent path form IIS etc.
But none of them is working. Please help me to solve this.
My current path :
crystalReport.Load(Server.MapPath("~/PurchaseOrder1.rpt"));
Not a whole answer but I'm too new to SO just to comment. One thing you could try is to download Process Monitor and watch to see where Crystal is trying to load the file from and that may help. Process Monitor will give a lot of output but that can be filtered on, for instance, part of the filename. It may tell you if there is a permissions issue too. I find it very useful for these sort of situations where you can't work out why a file is not found.
My guess is that the culprit may be a trailing / on the Webserver path.
Try using Path.Combine(Server.MapPath("~"), "PurchaseOrder1.rpt");
This should put appropriate / in the path and might fix your issue.
I think that the main difference with local and server environment is IIS root and the virtual directory that your application is located.
I mean, if the file is in the root of the site, you might want to use
crystalReport.Load(Server.MapPath("/PurchaseOrder1.rpt"));
OR you can try putting the rpt file into the same folder with ViewPurchaseOrder.aspx without changing the code
If it doesn't work, if you could share paths (both physical and virtual) we can check further.
*Edit: When using Server.MapPath
/ returns site root
~/ returns root directory of the application
The difference is that if your site is:
http://yoursite.com
And you have an application that's on wwwroot\somedir\app
So in your "app" (http://yoursite.com/somedir/app)
/ should return the root of the site (http://yoursite.com)
~/ should return the root of the application (http://yoursite.com/somedir/)
I have a .NET application that I am trying to debug and part of my application loads a file from my project. This file is located at
C:\Users\USER_FOLDER\Documents\Visual Studio 2012\Projects\MY_PROJECT\_templates\myFile.html
In my code, I specify a relative path to the file and use the DirectoryInfo class to get the full directory path to my file:
string myFile = (new DirectoryInfo("_templates/myFile.html")).FullName;
However, this returns the following path (extra \'s as escape characters):
"C:\\Program Files\\IIS Express\\_templates\\myFile.html"
I was expecting the path that is returned when debugging in IIS Express would match the first path I listed, not the third. Why is this? Is there something else that I need to set up in my project to have it derive the paths properly? I'm assuming that this would not happen if I deployed my code to a IIS7 site, but I haven't gotten to that testing level yet.
Use Server.MapPath:
Server.MapPath("~/_templates/myFile.html")
or HttpServerUtility.MapPath:
HttpServerUtility.MapPath("~/_templates/myFile.html")