Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Forgot to change the string virtualDir to ="/Images/". Doesn't make any difference since none of them work... :)
I'm trying to upload a file in code to a directory in my File Manager called "Images" but I can't seem to get the directory name right. Any suggestions to what I'm doing wrong? This is what I've got so far but it doesn't seem to find or create a directory name "Images".
protected string UploadFile(Stream fileContent, string fileName)
{
UnifiedDirectory dir;
string virtualDir = "/Diverse/";
if (HostingEnvironment.VirtualPathProvider.DirectoryExists(virtualDir))
dir = VirtualPathHandler.Instance.GetDirectory(virtualDir, true) as UnifiedDirectory;
else
dir = UnifiedDirectory.CreateDirectory(virtualDir);
if (dir != null)
{
UnifiedFile uFile = dir.CreateFile(fileName);
Stream s = uFile.Open(FileMode.CreateNew);
byte[] buffer = new byte[fileContent.Length];
int numBytesToRead = (int)fileContent.Length;
fileContent.Read(buffer, 0, numBytesToRead);
s.Write(buffer, 0, buffer.Length);
s.Close();
fileContent.Close();
return uFile.VirtualPath;
}
else return "";
}