Академический Документы
Профессиональный Документы
Культура Документы
2015
Fljoss:
AddingthedocumentidtothedocumentfilenameinSharePoint2010
(http://www.facebook.com/wombit.systemutveckling)
(http://www.twitter.com/wombitsys)
(https://plus.google.com/115253658878919191099)
(http://www.linkedin.com/company/wombitsystemutvecklingab)
SharePointAddingthebuiltinDocumentIDin
thedocumentfilename
(http://www.wombit.se/2013/10/24/sharepoint
2010documentidinfilename/)
October24,2013 TobiasEriksson(http://www.wombit.se/en/author/tobiaseriksson/)
SharePoint(http://www.wombit.se/tag/sharepoint2010/)
13Comments(http://www.wombit.se/2013/10/24/sharepoint2010documentidinfile
name/#disqus_thread)
Idiscoveredthatthishasbeendonemanytimesafterwedidit.Anyway,Iwillsharemyexperience.
Backin2010IwasinvolvedinaprojectwhichconsistedofcreatingastrictSharePointsitewithmetadata
orienteddocumentstorage.Nofolderswhatsoever,exceptfor10documentlibraries.Thisideawasntthat
hardtoimplementconsideringhoweasyitistocreatestaticmetadatainSharePointandaddingitto
ContentTypes.However,ifyouwanttoputalldocumentsinthesamecontainer,youwillhavetouse
uniquefilenames,otherwisefileswithsamenameswilloverwriteeachotherwithnewversions.
Now,howdoyoucreateauniquefilenamethatibasedonthefilenamewhichtheuserhasentered?Well,
youcanalwaysjustaddacustomIDorthelistitemIDintheendofthefilenameoryoucanusefolderslike
normalpeopleandpraythatnooneuploadsadocumentwithidenticalname.
InthiscasewehadalreadydecidedtouseSharePoint2010sbuiltinfeatureforgeneratingDocumentID.
ByusingthiswewillalsobeabletousesomeotherfeaturesthatisconnectedtotheDocumentID,like
searchandtheabilitytocreatedynamicURLs(whichiwillgetbackto).
OneoftherequirementswasthattheusershouldneverhavetoseetheirdocumentinSharePointwithout
theuniqueIDinthefilename.
Solvingtheproblemusingworkflow
Atfirst,wedidthisviaworkflowwhentheItemwascreatedbutweranintosomeissues.
Theworkflowsometimeskickedin10secondsaftertheitemwascreated.Iveseenthatthiscanbe
modified,butevenafterthatittooslow.
Iftheitemwasupdatedintheworkflow,theSystemAccountwouldhavebeenthemodifier.
Whenusers,aftersettingallmetadataandsavedtheform,theoldfilenamefromtheformwas
overwrittenwiththeonesetbytheworkflow.
Solvingtheproblemusingeventreceivers
http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/
1/6
27.5.2015
AddingthedocumentidtothedocumentfilenameinSharePoint2010
WhenuploadingadocumentinSharePointitwilltriggeracoupleofevents.Inourcase,wewereinterestedin
ItemAddingandItemAdded.
ItemAdding
WewantedtouseItemAddingwhenrenamingthefilesothatitwasrenamedwhentheeditformwasdisplayed.
Well,thereisnoiteminItemAddingsowerescrewedthere?!IwouldassumethatusingItemAddingwecould
manipulatethedatabeforetheactualcommit,butno.Andnotafterthebasecalleither.
ItemUpdating,ItemUpdated
Willnotbetriggeredwhenuploading.
ItemAdded
ThisistheeventthatistriggeredrightaftertheItemiscommittedtothedocumentlibrary,andthisiswhat
wehadtoworkwith.
YoucantchangetheSPFile.Namebecauseitsonlyget,youwillhavetochangetheNameField
(FileLeafRef)intheSPListItemproperties.Youwillalsohavetotriggeranupdateforthischangetocommit,
rememberthatthiswilltriggertheUpdateevents.
Ifyouwanttopreventtheupdateeventfromtriggeryoucanalwaysjustsetbase.EventFiringEnabledto
falseandbackagainaftertheupdateisdone.Amoreusefulwaytodothis,istomakeanIDisposeable
Classthatyoucanwrapyourupdatecodewithasshownintheexample.Thisisalsosomethingthatyou
couldusetopreventendlessloopsintheupdateevent.
Basicallyitwouldlooklikethis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
publicoverridevoidItemAdded(SPItemEventPropertiesproperties)
{
SPListItemitem=properties.ListItem;
stringdocumentId;
if(item.TryGetDocumentId(outdocumentId))
{
//Preventtheupdateeventsfromfiering
using(newDisableSPItemEvents())
{
//Getthefilenameandfileextension.
varfileName=item[SPBuiltInFieldId.BaseName];
varfileExt=item[SPBuiltInFieldId.File_x0020_Type];
varnewFileName=string.Format("{0}_{1}.{2}",fileName,documentId,fileExt);
//BaseNameireadonlysowewillsetthefilenamebacktoFileLeafRef
item[SPBuiltInFieldId.FileLeafRef]=newFileName;
//Updatethelistitemwithoutcreatinganewversion
item.SystemUpdate();
}
}
base.ItemAdded(properties);
}
publicclassDisableSPItemEvents:SPItemEventReceiver,IDisposable
{
publicDisableSPItemEvents()
{
this.EventFiringEnabled=false;
}
publicvoidDispose()
{
this.EventFiringEnabled=true;
http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/
2/6
27.5.2015
32
33
34
35
36
37
38
39
AddingthedocumentidtothedocumentfilenameinSharePoint2010
}
}
publicstaticboolTryGetDocumentId(thisSPListItemitem,outstringdocumentId)
{
documentId=item.Fields.ContainsField("_dlc_DocId")?(string)item["_dlc_DocId"]:null;
returndocumentId!=null;
}
Andtheresultisthis
(http://wombitse.azurewebsites.net/wp
content/uploads/2013/10/Documents.jpg)
Theendresult
Youhavetomakepeopleawarethatiftheywanttouploadadocumentandadditasanewversiontoan
existing,theyhavetorenamethefilelocallywiththeIDbeforeuploading.
AboutTobiasEriksson
http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/
3/6
27.5.2015
AddingthedocumentidtothedocumentfilenameinSharePoint2010
0Comments
Wombit
Recommend
Share
Login
SortbyBest
Startthediscussion
Bethefirsttocomment.
WHAT'STHIS?
ALSOONWOMBIT
ComputerVisionTachographcards
Part1
AngularJSDefiningControllerswith
JavaScriptandTypeScript
1comment2yearsago
1comment2yearsago
RogerAlsingnextpart:
DanielLidstrm Nicelyexplainedaboutthe
http://www.wombit.se/2013/10/2...
nestedscopewithngshow,Iwasnotaware
ofthatissue.Doyoubyanychancehavea
linktowheretheAngularJS
SharePointAddingthebuiltin
DocumentIDinthedocumentfilename
SharePointAddingthedocument
versionhistoryintoMSWord
13comments2yearsago
4comments2yearsago
TobiasErikssonHiHector,thiscanbe
HenriMerkesdalVerycreative!Iwould
donebycreatingaWorkflowinSharePoint
designer.Justcreateaworkflowandaddthe
followingaction"SetNameto
havesaidthatitcouldn'tbedone,buthereit
is:)Thanksforsharing!
Subscribe
Popular
AddDisqustoyoursite
Privacy
Recent
SharePointAdding
(http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/) thebuiltin
DocumentIDinthe
documentfilename(http://www.wombit.se/2013/10/24/sharepoint2010documentidinfile
name/)
October24,2013
SharePointOnline
(http://www.wombit.se/2013/12/07/sharepoint2013changetitlemicroblog/) ChangetheTitleofthe
newsfeedinthe
http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/
4/6
27.5.2015
AddingthedocumentidtothedocumentfilenameinSharePoint2010
SiteFeedWebPart(http://www.wombit.se/2013/12/07/sharepoint2013changetitlemicroblog/)
December7,2013
SharePointAddingthe
(http://www.wombit.se/2013/10/29/addingdocumentversionhistoryword/) documentversion
historyintoMSWord
(http://www.wombit.se/2013/10/29/addingdocumentversionhistoryword/)
October29,2013
SharePoint
(http://www.wombit.se/2014/06/13/sharepointcrudoperationsusingangularjsrest/) 2013/online
CRUD
operationsusingAngularJSandREST(http://www.wombit.se/2014/06/13/sharepointcrud
operationsusingangularjsrest/)
June13,2014
SharePoint
(http://www.wombit.se/2014/06/12/refreshformdigestvalueusingangularjsandrest/) Refresh
Form
DigestValueusingAngularJSandREST(http://www.wombit.se/2014/06/12/refreshformdigest
valueusingangularjsandrest/)
June12,2014
TAGS
Googleindex(http://www.wombit.se/tag/googleindex/) IIS(http://www.wombit.se/tag/iis/)
Bootstrap(http://www.wombit.se/tag/bootstrap/) ASP.Net(http://www.wombit.se/tag/aspnet/)
ContextMenuAction(http://www.wombit.se/tag/contextmenuaction/)
jQuery(http://www.wombit.se/tag/jquery/) jQueryUI(http://www.wombit.se/tag/jqueryui/)
AngularJS(http://www.wombit.se/tag/angularjs/)
Documentmanagement(http://www.wombit.se/tag/documentmanagement/)
C#(http://www.wombit.se/tag/csharp/) JavaScript(http://www.wombit.se/tag/javascript/)
CATEGORIES
Deployment(2)(http://www.wombit.se/category/deployment/)
IIS(1)(http://www.wombit.se/category/iis/)
Programming(11)(http://www.wombit.se/category/programming/)
SEO(1)(http://www.wombit.se/category/seo/)
SharePoint(10)(http://www.wombit.se/category/sharepoint2010/)
Uncategorized(2)(http://www.wombit.se/category/uncategorized/)
ARCHIVE
http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/
5/6
27.5.2015
AddingthedocumentidtothedocumentfilenameinSharePoint2010
June2014(http://www.wombit.se/en/2014/06/)April2014(http://www.wombit.se/en/2014/04/)
December2013(http://www.wombit.se/en/2013/12/)November2013(http://www.wombit.se/en/2013/11/)
October2013(http://www.wombit.se/en/2013/10/)
r eb r o
Post/besksadress
Oskarsparken1
70212rebro
Tel:(Telefon)0196090147
S t oc kh olm
Besksadress
Drottninggatan61
11121Stockholm
Tel:(Telefon)0840025687
(https://maps.google.com/maps?ll=59.298698,16.602972&z=9&t=m&hl=de-DE&gl=US&mapclient=apiv3)
Fehler bei Google Maps melden (https://www.google.com/maps/@59.2986981,16.6029718,9z/data=!10m1!1e1!12b1?source=apiv3&rapsrc=apiv3)
Kartendaten 2015 Google
http://www.wombit.se/2013/10/24/sharepoint2010documentidinfilename/
6/6