File Element (Module)

Specifies a file to include within a module in a site definition.

<File
  IgnoreIfAlreadyExists = "TRUE" | "FALSE"
  Name = "Text"
  NavBarHome = "TRUE" | "FALSE"
  Path = "Text"
  Type = "Text"
  Url = "Text >
</File>
Attributes

Attribute Description

IgnoreIfAlreadyExists

Optional Boolean. TRUE to provision the view even if the file aready exists at the specified URL; otherwise, FALSE.

Name

Optional Text. Specifies the virtual path for the file. Cannot contain the following characters:

  • \"

  • #

  • %

  • &

  • *

  • :

  • <

  • >

  • ?

  • \\

  • {

  • }

  • |

  • ~

  • \x7f

NavBarHome

Optional Boolean. TRUE if the file is the destination URL for the Home link in the top navigation bar used throughout the site.

Path

Optional Text. Specifies the physical path to the file relative to \\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Features\Feature. Can only contain the following characters:

  • alphanumeric

  • hyphen (-)

  • underscore (_)

  • period (.)

  • space ( )

Type

Optional Text. Specifies that the file be cached in memory on the front-end Web server. Possible values include Ghostable and GhostableInLibrary. Both values specify that the file be cached, but GhostableInLibrary specifies that the file be cached as part of a list whose base type is DocumentLibrary.

When changes are made, for example, to the home page through the UI, only the differences from the original page definition are stored in the database, while default.aspx is cached in memory along with the schema files. The HTML page that is displayed in the browser is constructed through the combined definition resulting from the original definition cached in memory and from changes stored in the database.

Url

Required Text. Specifies the virtual path for the file. If the Name attribute is specified, its value is used for the virtual path. If Path is not specified, the value of Url is used for the physical path. Cannot contain the following characters:

  • \"

  • #

  • %

  • &

  • *

  • :

  • <

  • >

  • ?

  • \\

  • {

  • }

  • |

  • ~

  • \x7f

Child Elements

Parent Elements

Occurrences

Minimum: 0

Maximum: Unbounded

Example

For an example of how this element is used, see Modules.

See Also

Other Resources

Module
Modules
How to: Provision a File

Tags :


Community Content

Daniel Flippance
Path vs Url

It seems to be that the Path is the location of the physical files relative to this Element Manifest file when installed in Sharepoint, and the Url is the virtual location of the file.  eg:

 

  <File Path="Images/bg_footer.jpg" Url="Style Library/Images/bg_footer.jpg"/>

Here, the filesystem looks like:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\MyFeature\Images\bg_footer.jpg

 

and the Http location looks like:

 

http://localhost/style%20library/images/bg_footer.jpg

Tags :

austegard
'Path' = Single Subfolder
While the word 'Path' normally conjures up something like some\directory\structure, given the limitations specifed above, Path can in fact only denote a single Folder.
I.e. you can place a file in the root of your feature folder, or in a subfolder, but not in a subfolder's subfolder (or beyond). If you place your file too deep in the folder hierarchy it will not be found when the feature is activated.
Tags :

Jay Arvin
IgnoreIfAlreadyExists parameter failing

Anyone else having trouble with the "IgnoreIfAlreadyExists" parameter?

I created a feature that adds a file to a site, then copied the feature so that I had a second that copies in exactly the same file. The idea being I could test this property. I modifed the file when installed in the second feature so that I could tell if it successfully ovewrote the version installed with the first feature.

Results were:

1) First feature successfully installed the file.

2) Second feature:

with: IgnoreIfAlreadyExists = TRUE : No error, but the file was not replaced

with: IgnoreIfAlreadyExists = FALSE : Error, telling me that the file already existed.

So, I'm snookered, I want to replace the file but it seems this functionality is not working. Is there a dependency I'm missing?

Thanks,

Daniel

I had the same problem! How did you resolve it in the end?

Adam

-----------------------

Regarding this, although it is possible to overwrite some files, it is not possible to overwrite all files using a featire. For a lot of the core files, if you try to overwrite them using a feature, the deployment of that file will be skipped. The best method is to create a custom file and then reference that instead of the original core file.

Bruce

___

I have the same problem, can you give example on how to go with that approach?

Jay Arvin

Ahmed F
IgnoreIfAlreadyExists parameter failing

I have the same problem with the IgnoreIfAlreadyExists. I have a feature that provision a pagelayout in the master page gallery. However changes can be made on the layout as part of the business requirements and we dont want to use SPD to modify the layouts. It is my understanding that using this attribute, when re-activating the feature, this should replace the pagelayout but based from our testing, it doesnt replace it.

Workaround:

The best way to get around this issue is to do a manual clean up for your feature. You should delete the file in the FeatureReceiver when you deactivate your feature using code. So, the old version would be deleted and you can provision the file again when your feature gets activated the second time.

Example:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
try
{
using (SPSite site = (SPSite)properties.Feature.Parent)
{
using (SPWeb web = (SPWeb)site.RootWeb)
{
foreach (SPList list in web.Lists)
{
if (list.RootFolder.Name.Equals("YourListRootFolder"))
{
SPDocumentLibrary docLib = (SPDocumentLibrary)list;
docLib.RootFolder.Files.Delete("YourPageName.aspx");
docLib.Update();
break;
}
}
}
}
}
catch (Exception ex)
{
// Error
}
}


johan leino
Re-add the file by parsing the xml

You can try this out:

http://johanleino.spaces.live.com/blog/cns!6BE273C70C45B5D1!304.entry?&_c02_vws=1

Tags :

Page view tracker