volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Upload file to page folder

Does anyone have an example of what code to use to upload a file to its page folder?

#42610
Aug 27, 2010 10:00

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();
}

#42611
Aug 27, 2010 10:10

Found it!

UnifiedDirectory dir = CurrentPage.GetPageDirectory(true);

#42629
Edited, Aug 27, 2010 12:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.