London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
Hi Per.
I usally use this approach:
public static void SaveFile(string newpath, byte[] bytes)
{
UnifiedDirectory dir;
string virtualDir = VirtualPathUtility.GetDirectory(newpath);
string virtualFile = VirtualPathUtility.GetFileName(newpath);
if (HostingEnvironment.VirtualPathProvider.DirectoryExists(virtualDir))
dir = VirtualPathHandler.Instance.GetDirectory(virtualDir, true) as UnifiedDirectory;
else
dir = UnifiedDirectory.CreateDirectory(virtualDir);
if (dir != null)
{
dir.BypassAccessCheck = true;
UnifiedFile newFile = dir.CreateFile(virtualFile);
Stream newImage = newFile.Open(FileMode.Create, FileAccess.Write);
newImage.Write(bytes, 0, bytes.Length);
newImage.Close();
}
}
newpath is the path to the new file, while bytes is the an bytearray of the file to save.
Hope this helps!
BR, Tore
Thanks for the help, you code send me in the rigth way
It seems that it was the path sting that was causing some problem in my case
/Per
Hi
A have a function that shall create a new UnifiedDirectory and then save file in it but a only get
System.NullReferenceException: Objektreferensen har inte angetts till en instans av ett objekt
when directory bellow is equal with null or do not exist.
Have found some links like
http://blog.fredrikhaglund.se/blog/2007/12/05/episerver-using-the-new-unified-file-system/
That did help a lot but this last part will not work hmmmm...
UnifiedDirectory directory = HostingEnvironment.VirtualPathProvider.GetDirectory(path) as UnifiedDirectory;
if (directory != null)
file2 = directory.CreateFile(VirtualPathUtility.GetFileName(this.m_targetPath));
else //this do not work
UnifiedDirectory ud = UnifiedDirectory.CreateDirectory(path);
file2 = ud.CreateFile(VirtualPathUtility.GetFileName(this.m_targetPath));