copy page from page llibrary to Record center document library
-
16 Maret 2012 17:35
hi,
i want to copy the pages from page library and document from document library to record center on updating the page event. for page associated to particular content type. can some one please help on this to copying the page to record center.
i want to do it via a code. on item update event.
regards Vimal
Semua Balasan
-
16 Maret 2012 17:58
you need work with Itemupdated event receiver of library.
http://karinebosch.wordpress.com/walkthroughs/event-receivers-walkthrough2/
http://www.chakkaradeep.com/post/Event-Receivers-in-SharePoint-2010.aspx
MCTS,MCPD Sharepoint 2010. My Blog- http://sharepoint-journey.com
If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful
- Diedit oleh Devendra Velegandla 06 Februari 2013 8:14
-
16 Maret 2012 18:20
thanks for quick reply,
but i am looking for code how to copy the record that is document and page with meta data to record center.
regards Vimal
-
17 Maret 2012 5:57
hi
i am having 2 site collection one as main site and other as record center, here is the code that i am trying to use
SPSite siteCollection = null;
SPWeb web = null;
try
{
siteCollection = new SPSite("Server");
web = siteCollection.OpenWeb("Site");
SPFile file = web.GetFile("Source_Folder_Name/Source_File");
String recordSeries = "";
String additionalInformation;
OfficialFileResult returnValue;
returnValue = file.SendToOfficialFile(recordSeries, out additionalInformation);}
-------
But it return me no success as return value... can any one please help me on this how to use SendToOfficialFile method.
regards Vimal
-
17 Maret 2012 6:39
use Exeception handling so that if there are any you can found those errors.
static void SendDocumentToRecordsCenterOM() { try { string AdditionalInformation = string.Empty OfficialFileResult OperationResult; Using(SPSite mySite = new SPSite("siteurl")) { Using(SPWeb myWeb = mySite.OpenWeb()) { SPFile myDoc = myWeb.GetFile("LibreryDoc/DocName.docx"); OperationResult = myDoc.SendToOfficialFile(out AdditionalInformation); Console.WriteLine("Operation State: " + OperationResult); } } } catch (Exception ex) { Console.WriteLine("Error - " + ex.ToString()); } }Please check the below link for more info:
MCTS,MCPD Sharepoint 2010. My Blog- http://sharepoint-journey.com
If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful- Diedit oleh Devendra Velegandla 06 Februari 2013 8:14
-
17 Maret 2012 6:50
hi
thanks for quick reply, Actually it is not throwing any error or exception, it just pass over the
myDoc.SendToOfficialFile(out AdditionalInformation);
line, but the document doesn't get copied to record center, but when i tried manually from UI using send to option it works.
And one more thing, I am trying this code as console application, to test if it work.
regards Vimal
- Diedit oleh singhal 17 Maret 2012 7:12
-
19 Maret 2012 19:04Hi Does the code you mentioned in your previous post will work for pages libray Also since I want to copy the aspx pages to archive record center. Or can you please suggest any alternative way to achieve this.
regards Vimal
-
20 Maret 2012 1:46
yes it should , please change
SPFile myDoc = myWeb.GetFile("LibreryDoc/DocName.docx");
to
SPFile myDoc = myWeb.GetFile("Pages/DocName.docx");
MCTS,MCPD Sharepoint 2010. My Blog- http://sharepoint-journey.com
If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful- Diedit oleh Devendra Velegandla 06 Februari 2013 8:15
-
20 Maret 2012 5:39
hi, thanks for quick reply,
but what i am looking for is
SPFile myDoc = myWeb.GetFile("LibreryDoc/DocName.aspx"); // aspx page
and it also works for me,
the code i am using is wirh run with elevated privilidge, so when the item got copied the modified by and created by data get change to system account. how can i retain the value of these 2 column and make the changes.
regards Vimal
- Diedit oleh singhal 20 Maret 2012 6:47 I got it working facing another issue
-
20 Maret 2012 8:08Hi, you can use the CopyTo method for copying the file to destination. on item updated event receiver.
Anil
-
20 Maret 2012 8:40
hi Anil,
This is not the solution that i am looking for, i need to copy the aspx page/ docx / any attach documnet to record center along with the metadata to Record center which is in the different site collection under same web application.
So i am using OfficialFileCore.SubmitFile (...) method to copy the file, but the problem is that i am able to copy the page and metadata but the 2 property
Created by and modified get updated to system account. i want this value to remain as original value.
here is the code
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteId))
{
using (SPWeb web = site.OpenWeb(webId))
{
SPFile file = properties.ListItem.File;
string fileType = properties.ListItem.ContentType.Name;
SPFieldCollection fields = file.Item.Fields;
List<Microsoft.SharePoint.RecordsRepositoryProperty> itemProperties = new List<Microsoft.SharePoint.RecordsRepositoryProperty>();
foreach (SPField spField in fields)
{
try
{
string fieldValue = file.Item[spField.Id] != null ? file.Item[spField.Id].ToString() : string.Empty;
string value = spField.GetFieldValue(fieldValue) as string;
Microsoft.SharePoint.RecordsRepositoryProperty property = new Microsoft.SharePoint.RecordsRepositoryProperty
{
Name = spField.Title,
Type = spField.TypeAsString,
Value = value
};
itemProperties.Add(property);
}
catch (ArgumentException) { }
}
string result = string.Empty;
SPSite ToSite = new SPSite("/sites/RecordCenter");
EcmDocumentRoutingWeb routingweb = new EcmDocumentRoutingWeb(properties.Web);
Microsoft.SharePoint.OfficialFileResult outcome = OfficialFileCore.SubmitFile(ToSite.OpenWeb(), file.OpenBinary(), itemProperties.ToArray(), fileType, file.Web.Url + "/" + file.Url, out result);if (outcome == Microsoft.SharePoint.OfficialFileResult.Success)
{
retVal = true;
}
}
}
});regards Vimal
-
20 Maret 2012 15:12
hi
got the solution for that
Microsoft.SharePoint.OfficialFileResult outcome = OfficialFileCore.SubmitFile(ToSite.OpenWeb(), file.OpenBinary(), itemProperties.ToArray(), fileType, file.Web.Url + "/" + file.Url, "username",False,out result); // used another overloaded method.
But now new problem i am facing, even though the code is with in Runwithelevated privilege if i update the page with the user having full access on site then the code run correctly, but if i try to modify the page with user having contribute access then it throw me exception as "Access denied" . even the code running as elevated privilege
(Setting : 1 web application having 2 site collection, one main site where the pages are and another site collection is record center)
can any one please help me on this. why i am getting the exception.
regards Vimal