How to copy a text file from a module to a document library that is not created, in SharePoint event receiver?

69 views Asked by At

I have a text file in module and I need to copy that file to a document library that is not existed yet, and it is going to be created in featureActivated. What should I do in this situation?

1

There are 1 answers

1
Lee On BEST ANSWER

Deploy to an existing library and then calling MoveTo in event receiver.

Sample demo:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MyModule" Url="MyDOc">
    <File Path="MyModule\Sample.txt" Url="Sample.txt" Type="GhostableInLibrary"/>  
  </Module>
</Elements>

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {           
            SPFile file = site.OpenWeb().GetFile("MyDOc/Sample.txt");
            file.MoveTo("/Shared%20Documents/Sample.txt");

        }