Hi Friends,
This is the functionality to upload document into sharepoint my site document library from document library with Document Set (multiple document for single item).
Document uploaded into current logged in user profile.
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
try
{
//get properties values from document set parent item in document library
SPList ObjStfList = properties.List;//["StaffSubmission"];
SPQuery query = new SPQuery();
query.Query = "" +
"" + properties.ListItem.Url.Split('/')[1] + "
";This is the functionality to upload document into sharepoint my site document library from document library with Document Set (multiple document for single item).
Document uploaded into current logged in user profile.
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
try
{
//get properties values from document set parent item in document library
SPList ObjStfList = properties.List;//["StaffSubmission"];
SPQuery query = new SPQuery();
query.Query = "
"
SPListItem stfListItems = ObjStfList.GetItems(query)[0];
if (stfListItems["Category"].ToString() == "Personal")
{
SPServiceContext context = SPServiceContext.GetContext(properties.Site);
UserProfileManager usrPrfMngr = new UserProfileManager(context);
//SPUser user = properties.Web.SiteUsers.GetByEmail(properties.UserLoginName.ToString());
//string strUserAcunt = user.LoginName.Split('|')[1];
string strUserAcunt = properties.UserLoginName.ToString().Split('|')[1];
UserProfile profile = usrPrfMngr.GetUserProfile(strUserAcunt);
web.Folders["StaffSubmission"].SubFolders[properties.ListItem["Name"].ToString()].Files;
SPFile sourceFile = properties.ListItem.File;
SPFile destFile;
// Copy file from source library to destination
using (Stream stream = sourceFile.OpenBinaryStream())
{
SPDocumentLibrary destLib =
(SPDocumentLibrary)profile.PersonalSite.RootWeb.Lists["Documents"];
destFile = destLib.RootFolder.Files.Add(sourceFile.Name, stream, false);
stream.Close();
}
// Update item properties
SPListItem destItem = destFile.Item;
SPListItem sourceItem = sourceFile.Item;
destItem["Title"] = stfListItems["Submission Title"];
destItem.UpdateOverwriteVersion();
}
}
catch { }
}
Thanks,
Regards,
Sathish.B
Comments
Post a Comment