Adam Shipp

System.NotSupportedException was unhandled
Message="The given path's format is not supported."
Source="mscorlib"
StackTrace:
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at MHA_Inspection.Automated_Processor.ProcessFiles(Object sender, EventArgs e) in C:\Documents and Settings\ashipp\My Documents\Visual Studio 2005\Projects\MHA Inspection\MHA Inspection\Automated Processor.cs:line 103
at MHA_Inspection.Automated_Processor.btnStart_Click(Object sender, EventArgs e) in C:\Documents and Settings\ashipp\My Documents\Visual Studio 2005\Projects\MHA Inspection\MHA Inspection\Automated Processor.cs:line 41
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MHA_Inspection.Program.Main() in C:\Documents and Settings\ashipp\My Documents\Visual Studio 2005\Projects\MHA Inspection\MHA Inspection\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

here is the code that I am using to do this:

string FILE_LOCATION = @"C:\\Documents and Settings\\ashipp\\My Documents\\a1teltest\\";
string ARCHIVE_LOCATION = @"C:\\Documents and Settings\\ashipp\\My Documents\\Archive\\a1teltest\\";
string
[] Files = Directory.GetFiles(FILE_LOCATION);
foreach (string file in Files)
{
string filename = ARCHIVE_LOCATION, name = "";
i = file.Length - 1;

// do some stuff

while
(i >= 0 && fileIdea != '/') // find beging of the actual file name
i--;
i++;
// get past the '/' that the while just found
while (i < file.Length) // put the file name into the name variable
name += file[i++];
filename += name;
// add the name of the file to the end of the archive location
File.Move(name, filename);
}

any help with this problem would be appreciated.




Re: Visual C# General File.Move(string1, string2) error

ahmedilyas

wow that is really nasty!

could I ask what you are actually trying to do (giving an example too)






Re: Visual C# General File.Move(string1, string2) error

Adam Shipp

as the code snippet shows, after I do some stuff with the file that is irrelevent as it does not change the file. I want to move that file to an archive folder. The top portion of my post is the message that the debugger gives me when I run the program. Everything upto and after that point works great.




Re: Visual C# General File.Move(string1, string2) error

ahmedilyas

sure. will see what can be done however I would suggest looking at what the filename is when the error happens




Re: Visual C# General File.Move(string1, string2) error

ahmedilyas

this is the output of the filename:

C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\RegexTests\\RegexTests\\bin\\Debug\\archiveC:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\RegexTests\\RegexTests\\bin\\Debug\\A.C.M.E. Secret Agent Bold.ttf

 

obviously, its incorrect

 

from what I understand, you want to move the current file into the archive directory Simply take the filename only:

System.IO.Path.GetFileName(file);

 

string FILE_LOCATION = @"C:\\Documents and Settings\\ashipp\\My Documents\\a1teltest\\";

string ARCHIVE_LOCATION = @"C:\\Documents and Settings\\ashipp\\My Documents\\Archive\\a1teltest\\";

string[] Files = Directory.GetFiles(FILE_LOCATION);

foreach (string file in Files)

{

File.Copy(file, ARCHIVE_LOCATION + "\\"+ System.IO.Path.GetFileName(file));

}

 

does this help






Re: Visual C# General File.Move(string1, string2) error

James Curran

string FILE_LOCATION = @"C:\\Documents and Settings\\ashipp\\My Documents\\a1teltest\\";

That should be either:

string FILE_LOCATION = "C:\\Documents and Settings\\ashipp\\My Documents\\a1teltest\\";

or

string FILE_LOCATION = @"C:\Documents and Settings\ashipp\My Documents\a1teltest\";

Either escape (double) the backslashes, or use the literal operator (@), but do not do both.






Re: Visual C# General File.Move(string1, string2) error

Adam Shipp

Thanks James, I had already figured that mistake out and changed it but did not feel the need to repost it.




Re: Visual C# General File.Move(string1, string2) error

Adam Shipp

Thanks Ahmedilyas! That worked like a charm. I believe that I owe you big. You solved my other problem yesterday too. Didn't you




Re: Visual C# General File.Move(string1, string2) error

ahmedilyas

heh no worries :-)




Re: Visual C# General File.Move(string1, string2) error

Adam Shipp

Opps! That gets the file copied just fine. Now I need to remove it from the original location so that the next time that this program automaticaly runs it won't redo the same file again.




Re: Visual C# General File.Move(string1, string2) error

ahmedilyas

well instead of Copy, use the Move method of the File class!

System.IO.File.Move(sourceFile, DestinationFile)

it will move the file rather than copying it






Re: Visual C# General File.Move(string1, string2) error

Adam Shipp

My real problem was that I was not closing the file before trying to move it. Stupid Beginers error. Can't believe I did that. Thanks for all of your help!!!!!!!!!