private string saveDrawingToFile(MemoryStream m, ref string error, ref long fileSize) { string path = ""; string fileName = ""; try { // Get the file name from GUID fileName = Guid.NewGuid().ToString() + ".pdf"; // Get the upload directory (both for upload and download) path = cpict.getUploadDirectory(fileName); using (FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write)) { byte[] bytes = new byte[m.Length]; m.Read(bytes, 0, (int)m.Length); file.Write(bytes, 0, bytes.Length); m.Close(); } FileInfo f = new FileInfo(path); fileSize = f.Length; } catch (Exception ex) { error = "Error when temporary storing drawing to a new file in the upload directory (" + path + "). Error message : " + ex.Message; fileName = "-1 " + ex.Message; } return(fileName); }