VsTeXProject.VisualStudio.Project.ProjectNode.SetEditLabel C# (CSharp) Method

SetEditLabel() public method

Renames the project node.
public SetEditLabel ( string label ) : int
label string The new name
return int
        public override int SetEditLabel(string label)
        {
            // Validate the filename. 
            if (string.IsNullOrEmpty(label))
            {
                throw new InvalidOperationException(SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture));
            }
            if (ProjectFolder.Length + label.Length + 1 > NativeMethods.MAX_PATH)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                    SR.GetString(SR.PathTooLong, CultureInfo.CurrentUICulture), label));
            }
            if (Utilities.IsFileNameInvalid(label))
            {
                throw new InvalidOperationException(SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture));
            }

            var fileName = Path.GetFileNameWithoutExtension(label);

            // if there is no filename or it starts with a leading dot issue an error message and quit.
            if (string.IsNullOrEmpty(fileName) || fileName[0] == '.')
            {
                throw new InvalidOperationException(SR.GetString(SR.FileNameCannotContainALeadingPeriod,
                    CultureInfo.CurrentUICulture));
            }

            // Nothing to do if the name is the same
            var oldFileName = Path.GetFileNameWithoutExtension(Url);
            if (string.Compare(oldFileName, label, StringComparison.Ordinal) == 0)
            {
                return VSConstants.S_FALSE;
            }

            // Now check whether the original file is still there. It could have been renamed.
            if (!File.Exists(Url))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                    SR.GetString(SR.FileOrFolderCannotBeFound, CultureInfo.CurrentUICulture), ProjectFile));
            }

            // Get the full file name and then rename the project file.
            var newFile = Path.Combine(ProjectFolder, label);
            var extension = Path.GetExtension(Url);

            // Make sure it has the correct extension
            if (string.Compare(Path.GetExtension(newFile), extension, StringComparison.OrdinalIgnoreCase) != 0)
            {
                newFile += extension;
            }

            RenameProjectFile(newFile);
            return VSConstants.S_OK;
        }
ProjectNode