C# "Could not find a part of the path" - Creating Local File
Posted
by Pyronaut
on Stack Overflow
See other posts from Stack Overflow
or by Pyronaut
Published on 2010-05-17T03:05:04Z
Indexed on
2010/05/17
3:10 UTC
Read the original article
Hit count: 303
I am trying to write to a folder that is located on my C:\ drive.
I keep getting the error of :
Could not find a part of the path .. etc
My filepath looks basically like this :
C:\WebRoot\ManagedFiles\folder\thumbs\5c27a312-343e-4bdf-b294-0d599330c42d\Image\lighthouse.jpg
And I am writing to it like so :
using (MemoryStream memoryStream = new MemoryStream())
{
thumbImage.Save(memoryStream, ImageFormat.Jpeg);
using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew))
{
memoryStream.WriteTo(diskCacheStream);
}
memoryStream.WriteTo(context.Response.OutputStream);
}
Don't worry too much about the memory stream. It is just outputting it (After I save it).
Since I am creating a file, I am a bit perplexed as to why it cannot find the file (Shouldn't it just write to where I tell it to, regardless?).
The strange thing is, It has no issue when I'm testing it above using File.Exists. Obviously that is returning false, But it means that atleast my Filepath is semi legit.
Any help is much appreciated.
© Stack Overflow or respective owner