Tagged Questions

A class of the Microsoft.SharePoint namespace that represents a file in a SharePoint Web site that can be a Web Parts page, an item in a document library, or a file in a folder.

learn more… | top users | synonyms

1
vote
1answer
40 views

How to get SPfile versions?

I'm making a .txt to store each version of a file after I perform a certain action. The code I'm running is simple: write("version number: 0.1"); write("modified : " + ...
1
vote
1answer
53 views

Why UniqueId missing in the REST api result from on-premise version

All, I found there is a property named UniqueId exist in the type of SP.File. And I try to retrieve the File item of the Page from SharePoint 2013 on-premise. The REST api url I used is ...
0
votes
0answers
23 views

Open file in Edit mode

I need to open a file in edit mode. In my web part on item click I need to do some action before hand (like create a folder and copy file, then open it in edit mode). I came across the code segment ...
1
vote
0answers
154 views

Add New & Edit Form to List via C#

I have a project that needs to associate custom New and Edit forms with list instances. The lists are not part of the project, but the custom forms are. I currently deploy them to ...
0
votes
0answers
99 views

Why is file still locked after successful SPFile.ReleaseLock()?

I want to lock a file, perform some operation on it, then unlock it. This is what I have so far (I do this in an item event receiver for ItemUpdating): try { ...
0
votes
2answers
43 views

Copy files between site collections

Following is my code (Console Application) which I am using to copy a file from a site collection to anohter. When I run the code again it says a file with name .. already exists in Style library but ...
0
votes
1answer
247 views

File gone after using SPFile.MoveTo

I am trying to move files from the RootFolder to a subfolder via PowerShell (would like to keep SPItem.Id from changing if possible). The code I have used is pretty straight forward. starting to ...
1
vote
1answer
229 views

How to Copy SPFile to another library while retaining history

I am looking for code that will 100% duplicate a file including all historical versions, dates of versions, comments and anything else. My test code is showing that capturing all those details is a ...
0
votes
1answer
1k views

Sharepoint 2013 ItemAdded event receiver for renaming files is not working

In SP 2013 I coded an event receiver that intercepts the ItemAdded event and it just renames the file. It is a synchronous event (I added Synchronous in the Elements.xml). This is the code: ...
0
votes
1answer
178 views

How to upload spfile to document library?

I am creating new web in the ItemAdded event receiver and I want to upload the picture that is attached with the item to the newly created site's picture library and if no attachment is there then I ...
0
votes
1answer
72 views

How can you get the thumnail URLS given the original image URL?

Given only a URL like /PublishingImages/lorem-ipsum.jpg how can i get the two thumbnail URLs? Both the _t and the _w thumbnail URLs?
3
votes
1answer
2k views

SPFile.CopyTo() vs RootFolder.Files.Add()

I've been looking for method of copying a file or folder from one document library to a number of other libraries with the same name in each subsite for a particular site collection. What needs to ...
0
votes
1answer
213 views

Every SPFile is null in a document library using PowerShell?

What the crap is this about? I whipped up a fairly simple run-once and discard PowerShell script to iterate through all of the files in a list and make a simple change. The problem is every SPFile I ...
0
votes
1answer
184 views

Retrieve previous file contents on ItemUpdated

I am writing an event receiver on a document library. I need to get the previous version of the document, before the upload. BeforeProperties unfortunately does not give me the SPFile, only the ...
2
votes
1answer
148 views

Access Anonymous to spSite.RootWeb.Folder[“xx”] in sharepoint 2010

I wrote that method to download file from document library. But When I enter site as annonymous and try to download file, "site.RootWeb.Folders["Dokumanlar"];" this code wants authentication. In ...
1
vote
2answers
1k views

Appending text to an SPFile in document library (creating file if necessary)

Here is the setup. On error i want to write (append) the error message to an SPFile in a document library. If the file doesn't already exist i want to create it. Searching around this is what i ...
1
vote
1answer
4k views

Get all documents from a sharepoint document library

I want to retrieve all the existing documents from an SPDocumentLibrary in order to print them so I've tried this way but then I got stucked : using (SPSite mysite = SPContext.Current.Site) { ...
0
votes
2answers
578 views

Differentiate in ItemUpdated (ER) if file was edited or overwritted

I've an ItemUpdated Event Receiver, and I need to make different operations depending if the file was updated throw UI or overwritted. Is there any internal field that reflects this 2 different ...
1
vote
2answers
2k views

Get file from any library in the web tree

Is it possible to use some built in SharePoint API to open a file no matter which web and library it's in? Example: Given the file: /subsiteA/PublishingImages/myimage.jpg I want to open it and get ...
1
vote
1answer
2k views

How to unlock a SPFile.SPCheckedOutStatus.ShortTerm lock on a ListItem on both Sharepoint 2007 and 2010

How can a site administrator remove a short term lock on a SPListItem.SPFile object? This happens when a user opens a Office document for editing from a list without doing a checkout. If the user does ...
1
vote
3answers
5k views

Getting specific SPFile from document library

I have a Document Library called "x" with file named "y". I am curious what the best way to get the SPFile object for the specified SPListItem. Currently I am using this: ...
2
votes
1answer
1k views

SPFile.OpenBinary throwing error “Cannot open file”

I have the chunk of code below: SPListItem source = //some list item; foreach (string file in source.Attachments) { SPFile oFile = source.Web.GetFile(file); string strFilename = oFile.Name; ...
0
votes
1answer
368 views

SPFile Update fails, Exists returns true

I have a block of code wrapped in an if: mySite.AllowUnsafeUpdates(); SPFile mySPFile = web.GetFile(someURL); if (mySPFile.Exists) /*returns true, enters code block*/ { //... make some updates ...
2
votes
0answers
98 views

Error thrown after SaveBinary in ItemAdded event handler

I'm working on a ItemAdded event for a document library, and I'm running into this error in SharePoint 2007... The file Lists/Shared Audit Documents/1387/Audit Report.docm has been modified by ...
0
votes
1answer
1k views

Looking for a way to replace the File in an SPListItem

I have implemented a system for publishing documents from a document library to a Document Centre. This uses a Send To Connection set up with the "Move and leave a link" option. When this is used the ...
1
vote
1answer
1k views

Programmaticly updating SPFileVersion.Properties Hashtable

Anyone who has experience with programmaticly updating the SPFileVersion.Properties Hashtable? I have a special situation where I would like to modify this Hashtable. Most of you will say: "Why on ...
3
votes
3answers
2k views

Copying file from network to Document Library

I'm trying to save file from network location to SharePoint document library. This is code of my method: //parameters: string documentLibraryUrl, string filePath FileInfo fi = new ...
0
votes
1answer
556 views

SPWeb.GetFile for an old version of file

I have a document library with enabled versioning, I added an xml file, then added it again, but I have edited one value in it. Now I would like to get the content of both files in C# to compare them. ...
6
votes
2answers
2k views

SPListItem.SystemUpdate updates SPListItem.File.ModifiedBy

As can be seen from the debug image when I call SystemUpdate(false) of a SPItem, that SPItem's File object's ModifiedBy attribute changes to "SHAREPOINT\system". Sorry, it's a bit weird way to ...
0
votes
1answer
662 views

using SPFile page.Exists sometimes asks user to sign in

I'm working on a custom 404 page for a new public facing SharePoint site which is replacing our current non-SharePoint site. Customers may have bookmarks that will break on the new site, simply ...
1
vote
1answer
2k views

SPFile file = web. GetFile (fileUrl); but sometimes they pass in incorrect fileUrl

Will this work or break if fileUrl is blank or does not even exists? SPFile file = web. GetFile (fileUrl); if (file == null) { file.delete() }
5
votes
3answers
530 views

Access binary data of an SPFile through an SPMetal generated entity

I've used SPMetal to generate my DataContext and classes for my custom Content Types. Some of these Content Types derive from Document content type. I need to run a Linq query against a Document ...
0
votes
1answer
306 views

Copying a document between libraries breaks QuickParts

I am copying a file between 2 libraries which contain the same fields. So basically the source library serves as a template library. After the file is copied i update the field values in the ...
18
votes
3answers
5k views

Find Document by GUID

I'm missing something that must be so simple that it's not even worth asking... but I have an object ID (GUID)... How do I figure out the document it points to? For example I have a GUID of ...
2
votes
3answers
2k views

Attempt to get property CheckOutType of SPFile cause 'System.NullReferenceException' exception

I have a strange situation: If the "Require Check Out" and "Create Major Versions" options are switched on for the current Document Library, then when I try to get the CheckOutType property I receive ...