HLOOV TSHIAB: Qhov no xwb, tiam sis yog muaj teeb meem loj uas muaj nyob rau hauv cov lus muaj. Qhov no tseem yuav pab tau rau ib co cirumstances.
HLOOV TSHIAB 2: Nyob rau hauv kuv qhov project no, cov neeg siv yuav tsum upload ntaub ntawv. Yog li ntawd, Kuv tsis tau khiav mus rau ib qho teeb meem uas MS Word khiav khiav thiab xav tias tias cov ntaub ntawv yog renamed rau. Kuv puas tau khiav mus rau ib qho teeb meem, "cov ntaub ntawv yog hloov los ntawm lwm tus" thiab solved no ntawm tus chij hom lus semaphore. Cov neeg siv yuav tsum tau hloov meta cov ntaub ntawv teb nws vim nqi tam sim no los yog lwm yam. Lub itemupdated() receiver zoo rau ib tug siv tau nqi muaj ua ntej ua tau lub rename thiab txij thaum ntawd los, Kuv tsis tau muaj tej teeb meem. Koj nqi kev mus yuav txawv.
Kuv muaj ib tug neeg yuav tsum tau hloov lub npe ntawm cov ntaub ntawv rau lub tsev qiv ntawv tej ntaub ntawv los yoog tau nrog ib tug naming convention uploaded. API tsis muab "rename ib()" txujci. Xwb, peb siv "MoveTo(…)". Ntawm no yog qhov chaw cia me ntsis ntawm txoj kev yuav ua kom tiav no:
pej xeem override khoob lug ItemAdded(SPItemEventProperties khoom) { SPFile f = zog.ListItem.File; f.MoveTo(zog.ListItem.ParentList.RootFolder.Url + "/xyzzy.doc"); f.Update(); } |
Lub ntsis xwb lo yog cov "khoom. ListItem.ParentList.RootFolder.Url". Lub MoveTo() txoj kev yuav tsum tau ib qhov URL. Uas mashed txog cov ntsiab lus txoj hlua kuv rau cov hauv paus hniav sis ntawm kuv lub tsev qiv ntawv ntawv tam sim no. Qhov no pub rau kuv kom tsis txhob muaj zog coding nyob hauv kuv tej receiver.
Qhov no yog ib pab tau ntau version ntawd puas muaj qhov tib, tab sis, tus assigns lub npe ntawm cov ntaub ntawv rau lub "Title":
pej xeem override khoob lug ItemAdded(SPItemEventProperties khoom) { DisableEventFiring(); // Cob lub npe ntawm cov khoom no rau lub npe ntawm cov ntaub ntawv xwb. // CEEB TOOM: No ntus yuav tsum xyuas ua ntej peb hloov cov ntaub ntawv xwb. // Hu rau cov hloov tshiab() nyob rau hauv SPFile pom lawm hais tias invalidate cov khoom nyob rau hauv // tej kev txiav txim zoo. Tshiab rau "Title" ua tsis tau tejyam kom txog thaum uas hloov (thiab hloov tshiab() hu) // tau tsiv pem lub taub hau ntawm kev hloov rau cov ntaub ntawv npe. zog.ListItem["Title"] = zog.ListItem.File.Name; zog.ListItem.Update(); SPFile f = zog.ListItem.File; // Tau ncua ntxiv ntawm cov ntaub ntawv. Peb xav tias tom qab. hlua spfileExt = tshiab FileInfo(f.Name).Extension; // Rename ntawv los sau yam tus ID thiab siv tau ua ntaub ntawv thov ncua ntxiv kom // tias ib feem ntawm nws lawm. f.MoveTo(zog.ListItem.ParentList.RootFolder.Url + "/" + zog.ListItem["TUS ID"] + spfileExt); // Kuas cov qhov nyuas siv zug. f.Update(); EnableEventFiring(); } |