I have some code that I am using to create a Document Set when a document is uploaded into a library. The document set is created within the library...I am currently doing this in an event receiver (ItemAdded). The problem i am having is...when the document is uploaded, I want the user to be prompted for some metadata, which will help determine which block of code to be executed and i can't seem to get this done. Is there a way to get the logic to get the metadata before executing the rest of the code?
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = properties.Web; SPListItem listItem = properties.ListItem;
SPList myList = listItem.ParentList;
SPFolder mylibrary = myList.RootFolder;
SPList FirstList = currentWeb.Lists["First List"];
SPList SecondList = currentWeb.Lists["Second List"];
var IsAFolder = IsFolder(listItem);
//1. Check to see if object added is a document
if (IsAFolder == false)
{
this.EventFiringEnabled = false;
string EmployeeName = listItem["Employee Name"].ToString();
string EmployeeID = listItem["Employee ID"].ToString();
string DocumentSetName = EmployeeID;
string DocumentType = listItem["Document Type"].ToString();
SPFile fileSource = listItem.File;
string EmailAddress = FirstList.Fields["Email List"].ToString();
string FromEmail = SecondList.Fields["From"].ToString();
string EmailSubject = SecondList.Fields["Subject"].ToString();
string EmailBody = SecondList.Fields["Body"].ToString();
//2. Evaluate the Document Type
if (DocumentType == "Assessment")
{
//execute some block of code
}
else if (DocumentType == "Certification")
{
//execute some other block of code
}
else
{
//bla bla bla.
}
}
}
});
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("My Category", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
finally
{
}
}Part of the metadata that is entered by the user is the "Document Type", and I want specific blocks to be executed depending on what the document type entered is. Right now, i can get this to work the way it is designed cause the metadata input screen is popping up at the very end. What am I missing?
Thanks for the help