Velox & Facile: TRANSNOMINO Uploaded File Usura SharePoint Objectiva Pe Via res Receptor

UPDATE: This works but there are significant limitations which are described in the comments. This may still be useful in some cirumstances.

UPDATE 2: In current project, users always upload documents. Ut ex, I don’t run into a problem where MS Word is running and thinks that the file was renamed on it. I did run into a problem, "the file was modified by someone else" and solved this via a simple semaphore type flag. Users need to change a meta data field from its default value to something else. The itemupdated() accipientem spectat ad validam valorem ante TRANSNOMINO in actu perfecto, et tunc cum, I have not had any problems. Your mileage may vary.

I have a client requirement to change the name of files uploaded to a specific document library to conform with a particular naming convention. The API does not provide a "rename()" methodo. Pro, Utimur "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 publica dominari Irrita ItemAdded(SPItemEventProperties Proprietates)
        {
            SPFile F = properties.ListItem.File;

            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url + "/xyzzy.doc");
            f.Update();

        }

The only tricky bit is the "properties.ListItem.ParentList.RootFolder.Url". The MoveTo() method requires a URL. That mashed up string points me to the root folder of my current document library. This allows me to avoid any hard coding in my event receiver.

Latin utilior est idem facit, but assigns the name of the file to "Title":

 publica dominari Irrita ItemAdded(SPItemEventProperties Proprietates)
        {
            DisableEventFiring();

            // Titulus autem huius assignant item nomen file ipsum.
 // MONUMENTUM: Hac assignatione fieri oportet ante se temperare file.
 // Vocans update() in SPFile videtur infirmatione proprietatum
 // quaedam.  Updates to "Title" donec deficerent mutabilibus (et update() voca)
 // Nomen fasciculi ad commutationem pro motis.
            properties.ListItem["Title"] = Properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile F = properties.ListItem.File;

            // Impetro file extensionem.  Nos postulo ut postea.
 filum spfileExt = novum File Info(f.Name).Extensio;

            // TRANSNOMINO lima ut album Item ID scriptor utor lima tractus custodire
 // intactam illam partem.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // Committere movéntur.
            f.Update();

            EnableEventFiring();
        }

4 cogitationes on "Velox & Facile: TRANSNOMINO Uploaded File Usura SharePoint Objectiva Pe Via res Receptor

  1. Non nomen
    Quoque, Verbum interius si feceris, et revertetur ad errorem non dico limae. Non est adnuntiatum de novum URL. Per id quod nondum invenit.
  2. Paulus Galvin
    Thanks for pointing that out. I don’t know an answer to that one either … ad quam Cn sit amet.
    ITERUM: async & Inimicus
    I wonder if moving it to an ItemAdding will solve it. That’s a big hole.
    Gratias!
    –Paulus
  3. Nadeem Mitha
    Quia file movetur gets asynchronously, est facultas redirected coram moventur committitur ad EditForm.aspx (et qui malis). You’ll see that this happens if you make the code sleep before the MoveTo line. I still haven’t figured out what can be done about that problem aside from using a customized edit form.

Aliquam

Tua inscriptio electronica non editis. Velit sunt insignis *