Ceev & Yooj yim: Rename Uploaded tej ntaub ntawv uas siv SharePoint kwv tus qauv ntawm ib cov Receiver Event

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();
        }

4 xav txog"Ceev & Yooj yim: Rename Uploaded tej ntaub ntawv uas siv SharePoint kwv tus qauv ntawm ib cov Receiver Event

  1. Directory lub website
    Zoo kawg thiab ntaus tej ncauj lus txog taw tes qhia tawm los sis qhia tawm cov ntaub ntawv!
    Kuv tsis tau txais nws!
    Teb
  2. Tsis muaj lub npe
    Kuj, Yog koj ua li no los tom qab lo lus, nws yuav rov qab muaj ib qho kev ua yuam kev thiab hais tau cov ntaub ntawv tsis nyob ua ib ke. Nws yuav tsis paub txog qhov URL tshiab. Kuv tsis tau pom muaj ib txoj kev nyob ib ncig ntawm no.
    Teb
  3. Paul Galvin
    Tsaug rau taw uas. Kuv tsis paub yuav teb kom tau ntawd ib tug yog … yuav tsum saib yuav tswj tau nws nthuav.
    RE: async & mus
    Kuv xav tias nws tsiv mus nyob dua ib lub ItemAdding yuav daws tau. Uas yog qhov loj.
    Tsaug!
    –Paul
    Teb
  4. Nadeem Mitha
    Vim tias cov ntaub ntawv twg thiaj li raug hloov mus asynchronously, yog ib tug tseem ceeb redirected los EditForm.aspx ua ntej qhov uas tsis muaj (yog tsis zoo). Koj yuav pom tias zoo li no yog hais tias koj ua lub chaws pw ua ntej ntawm cov kab MoveTo. Kuv tseem tsis tau figured seb yuav ua li cas txog qhov teeb meem hauj siv daim hloov customized.
    Teb

sau ntawv cia

Koj email chaw nyob yuav tsis muab luam tawm. Search cim *