private void ClearWWWRootTempFolder() { DirectoryInfo di = new DirectoryInfo(RootDirectoryTools.GetWWWRootTempFolderPhysicalPath()); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in di.GetDirectories()) { dir.Delete(true); } }
private string GenerateTempImageAndTempPath(string imagePath) { // If the camera has a value in the image_path column of the Camera table in the database, if not a question mark will be displayed instead. if (String.IsNullOrWhiteSpace(imagePath) == false) { // Ensure the image file still exists on the server, if not a question mark will be displayed instead. if (File.Exists(imagePath)) { /* * NOTE: To create/delete/overwrite file in the wwwroot directory, physical file paths must be used * and not virual paths (using ~). Use RootDirectoryTools.cs in HelperServices. */ // 1. Extract the FileName from the path stored in the database. string fileName = Path.GetFileName(imagePath); // 2. Create the full file output path (physical). string tempPath = Path.Combine(RootDirectoryTools.GetWWWRootPhysicalPath(), fileName); // 3. Delete any previous file in the temp folder associated to the camera. if (File.Exists(tempPath)) { File.Delete(tempPath); } // 4. Copy the image from the path in the "...\BackEnd\BackEndServer\ImageStorage\CameraImages" to the phycal wwwroot path's "\temp" folder. File.Copy ( // Source Image Path (stored in the ImageStorage\CameraImages folder in the project.) imagePath, // Write to the wwwroot directory's temp path (physical), output filename remains the same. Path.Combine(RootDirectoryTools.GetWWWRootTempFolderPhysicalPath(), fileName), // If file was not deleted properly, ensure the existing file is overwritten. true ); // 5. Set the View Model object's "TempImagePath" attribute to the appropriate // value for use in the img element's src attribute to locate the image in the wwwroot. return(String.Concat(RootDirectoryTools.GetWWWRootTempFolderVirtualPathForHTML(), "/", fileName)); } } return(null); }