FileStore.FileStore.CreateFile C# (CSharp) Method

CreateFile() public method

Creates a file.
public CreateFile ( string path ) : StoreFile
path string The file path.
return StoreFile
        public StoreFile CreateFile(string path)
        {
            if(path == null) {
                throw new ArgumentNullException("path");
            }

            string[] components = path.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
            if(components.Length == 0) {
                return null;
            }

            string fileName = components[components.Length - 1];
            StoreFolder folder = GetFolder(path.Substring(0, path.Length - fileName.Length));

            // check if the folder contains the file
            if(folder.Files.ContainsKey(fileName)) {
                return files[folder.Files[fileName]];
            }

            // add the file
            StoreFile file = new StoreFile(fileName);
            Guid fileId = Guid.NewGuid();
            folder.Files.Add(fileName, fileId);
            files.Add(fileId, file);

            return file;
        }