விரைவான & எளிதாக: ஒரு நிகழ்வு ரிசீவர் மூலம் ஷேர்பாயிண்ட் ஆப்ஜெக்ட் மாதிரி பயன்படுத்தி Uploaded கோப்பு மறுபெயரிட

புதுப்பிப்பு: This works but there are significant limitations which are described in the comments. This may still be useful in some cirumstances.

புதுப்பிப்பு 2: என் தற்போதைய திட்டம், users always upload documents. இதன் விளைவாக, 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() ரிசீவர் உண்மையில் பெயர்மாற்றுதல் செய்ய முன் மற்றும் பின் அங்கு சரியான மதிப்பு தெரிகிறது, 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()" முறை. பதிலாக, நாம் பயன்படுத்த "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 பொது புறக்கணி களைவதற்கு ItemAdded(SPItemEventProperties பண்புகள்)
        {
            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.

அதே விஷயம் என்று ஒரு பயனுள்ள பதிப்பு, but assigns the name of the file to "Title":

 பொது புறக்கணி களைவதற்கு ItemAdded(SPItemEventProperties பண்புகள்)
        {
            DisableEventFiring();

            // கோப்பு தன்னை பெயர் இந்த உருப்படியை தலைப்பு ஒதுக்கு.
 // குறிப்பு: நாங்கள் கோப்பு தன்னை மாற்ற முன் இந்த ஒப்பந்தம் நடக்க வேண்டும்.
 // மேம்படுத்தல் அழைப்பு() SPFile மீது பண்புகள் நீக்கம் தெரிகிறது
 // சில உணர்வு.  Updates to "Title" அந்த மாற்றம் வரை தோல்வி (மற்றும் மேம்படுத்தல்() அழைப்பு)
 // கோப்பு பெயர் மாற்றம் முன்னால் சென்றார்.
            properties.ListItem["Title"] = Properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile F = properties.ListItem.File;

            // கோப்பு நீட்டிப்பு கிடைக்கும்.  நாம் பின்னர் அந்த வேண்டும்.
 மாலை spfileExt = புதிய FileInfo(f.Name).நீட்டுதல்;

            // பட்டியல் உருப்படியை அடையாள கோப்பு பெயரை வைத்து கொள்வது கோப்பு நீட்டிப்பு பயன்படுத்த
 // அப்படியே அது அந்த பகுதி.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // நடவடிக்கை உறுதி.
            f.Update();

            EnableEventFiring();
        }

4 "மீது எண்ணங்கள்விரைவான & எளிதாக: ஒரு நிகழ்வு ரிசீவர் மூலம் ஷேர்பாயிண்ட் ஆப்ஜெக்ட் மாதிரி பயன்படுத்தி Uploaded கோப்பு மறுபெயரிட

  1. எந்த பெயர்
    மேலும், நீங்கள் வேர்ட் இருந்து இதை செய்தால், இது ஒரு பிழை திரும்ப மற்றும் கோப்பு இல்லை என்று கூறுவேன். இது புதிய URL பற்றி கூறினார். நான் இன்னும் இந்த சுற்றி ஒரு வழி இல்லை.
  2. பால் கால்வின்
    Thanks for pointing that out. I don’t know an answer to that one either … அதை நிர்வகிக்க எப்படி பார்க்க சுவாரசியமான இருக்கும்.
    RE: async & திருப்பிவிட
    I wonder if moving it to an ItemAdding will solve it. That’s a big hole.
    நன்றி!
    –பால்
  3. நதீம் Mitha
    கோப்பு ஒத்தியங்காமல் சென்றார் ஏனெனில், EditForm.aspx திருப்பிவிடப்பட்டது என்று ஒரு வாய்ப்பு நடவடிக்கை உறுதி முன் உள்ளது (அந்த மோசம்). 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.

ஒரு பதில் விட்டு நதீம் Mitha பதிலை நிருத்து

உங்கள் மின்னஞ்சல் முகவரி வெளியிடப்பட்ட முடியாது. தேவையான புலங்கள் குறிக்கப்பட்டன *