-1

I am trying to add file type validation in "add existing item" in solution explorer in visual studio experimental instance. If the selected file type is not valid, then it needs to display message box like invalid file type. Else it needs to add the file to the project.

Currently by using this "VS.Events.ProjectItemsEvents.AfterAddProjectItems", it is adding the file before validating file type.

Is there any visual studio event to call at the time of "add existing Item" to validate?

2
  • Is there a BeforeAddProjectItems event or the like? Commented Feb 6, 2024 at 6:53
  • Hi Meghana, have you tried to implement your custom validation logic by creating a sperate menu ? Commented Feb 22, 2024 at 3:25

1 Answer 1

0

Is there any visual studio event to call at the time of "add existing Item" to validate?

I am afraid that there is not a specific Visual Studio event that fires before items are added during the "Add Existing Item" process.

If you want to validate file type before adding files to projects/solution,here is a workaround:

you can implement your custom validation logic by creating a separate menu like "validate file type".

1.Create a custom menu item in your extension.

https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-menu-command?view=vs-2022

2.Validate the file type based on its file type. If the file type is invalid, show a message box with an appropriate error message. Otherwise, add the file to the project programmatically.

string fileExtension = Path.GetExtension(fileName).ToLower();
if (Array.IndexOF([".pdf", ".doc", ".docx"],fileExtension) == -1 )
{
 // error message
}else{
// add file to project
}

Hope it can help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.