cancel
Showing results for 
Search instead for 
Did you mean: 

Utility.WriteStreamToFile and a new subfolder as part of the UNC path

Nick_McElheny1
Star Contributor
Star Contributor

Hi all,

I'm trying to write a file to a network share using the Unity API.  The code works great if the entire path exists.  If a portion of it doesn't, I receive the following error:

"Could not find a part of the path"

My goal is to have the file go in to a subfolder on this UNC path which is named after one of the keywords.  Is there a way to make Utility.WriteStreamToFile work if one of the subfolders in the path needs dynamically created?

We are running 13.0.0.37.

Thanks,

Nick McElheny

2 REPLIES 2

Justin_Walker
Champ in-the-making
Champ in-the-making

Hi Nick,

I would use Directory.Exists()  to check your path, then use Directory.CreateDirectory() to create the path if it doesn't exist.  CreateDirectory will also create any directories in the path that don't exist yet. Then you can use WriteStreamToFile for that path. [http://msdn.microsoft.com/en-us/library/System.IO.Directory_methods.aspx]

Thanks,

Nick_McElheny1
Star Contributor
Star Contributor

Justin,

That did just the trick.  Thanks!!