-
-
Save parth7676/468885258446de10f1837ee5f9dfd334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileUtility : IFileUtility | |
{ | |
public string SaveFile(string fileName,byte[] fileStream) | |
{ | |
string path = null; | |
string imageFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), "ProductImages"); | |
//Check if the folder exist or not | |
if (!System.IO.Directory.Exists(imageFolderPath)) | |
{ | |
System.IO.Directory.CreateDirectory(imageFolderPath); | |
} | |
string imagefilePath = System.IO.Path.Combine(imageFolderPath, fileName); | |
//Try to write the file bytes to the specified location. | |
try | |
{ | |
System.IO.File.WriteAllBytes(imagefilePath, fileStream); | |
path = imagefilePath; | |
} | |
catch (System.Exception e) | |
{ | |
throw e; | |
} | |
return path; | |
} | |
public void DeleteDirectory() | |
{ | |
string imageFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), "ProductImages"); | |
if (System.IO.Directory.Exists(imageFolderPath)) | |
{ | |
System.IO.Directory.Delete(imageFolderPath,true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment