-
-
Save parth7676/30fd7c1c297107655019570bd723635b 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[] imageStream) | |
{ | |
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, imageStream); | |
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