SenseNet.ContentRepository.Storage.RepositoryPath.GetParentPath C# (CSharp) Метод

GetParentPath() публичный статический Метод

Gets the parent path from a path.
public static GetParentPath ( string path ) : string
path string The path.
Результат string
        public static string GetParentPath(string path)
        {
            if (string.IsNullOrEmpty(path))
                return string.Empty;

            var index = path.LastIndexOf(PathSeparator, StringComparison.Ordinal);
            return index <= 0 ? string.Empty : path.Substring(0, index);
        }

Usage Example

Пример #1
0
        private static Exception SavingExceptionHelper(NodeData data, Exception catchedEx)
        {
            if (data.Id != 0)
            {
                var message = "The content cannot be saved.";
                if (catchedEx.Message.StartsWith("Cannot insert duplicate key"))
                {
                    message += " A content with the name you specified already exists.";

                    var appExc = new NodeAlreadyExistsException(message, catchedEx); // new ApplicationException(message, catchedEx);
                    appExc.Data.Add("NodeId", data.Id);
                    appExc.Data.Add("Path", data.Path);
                    appExc.Data.Add("OriginalPath", data.OriginalPath);

                    //if (catchedEx.Message.StartsWith("Cannot insert duplicate key"))
                    appExc.Data.Add("ErrorCode", "ExistingNode");
                    return(appExc);
                }
                return(catchedEx);
            }
            var head = GetNodeHead(RepositoryPath.Combine(RepositoryPath.GetParentPath(data.Path), data.Name));

            if (head != null)
            {
                //var appExp = new ApplicationException("Cannot create new content. A content with the name you specified already exists.", catchedEx);
                var appExp = new NodeAlreadyExistsException("Cannot create new content. A content with the name you specified already exists.", catchedEx);
                appExp.Data.Add("Path", data.Path);
                appExp.Data.Add("ErrorCode", "ExistingNode");

                return(appExp);
            }
            return(catchedEx);
        }