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
In the SDK you can find a code for uploading a file. Is there any way to modify this to save to the page folder?
protected void UploadFile(Stream fileContent, string fileName, string destinationPath)
{
UnifiedDirectory dir = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(destinationPath) as UnifiedDirectory;
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();
}
Found it!
UnifiedDirectory dir = CurrentPage.GetPageDirectory(true);
Does anyone have an example of what code to use to upload a file to its page folder?