Skip to main content

Questions tagged [spfile]

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.

Filter by
Sorted by
Tagged with
1 vote
0 answers
126 views

How to move a file programmatically and preserve full version history (including users!)?

I have a document approval system that works something like this: User uploads a document to one library, fills out metadata. Approval process begins, workflows are fired to send out notification ...
Dylan Cristy's user avatar
  • 12.8k
1 vote
0 answers
51 views

SharePoint C# move attachment and keep creation values in SP 2019

We want to copy item attachments from one Item in one site collection to another item in a different site collection using C# (Server Side Object Model). Is it possible to keep or replicate the ...
Mike's user avatar
  • 245
3 votes
1 answer
153 views

How to check the file is used by another process?

In sharepoint from Document library i was read the file and Download the file using FileStream object. Sometime it was downloading. Sometime i will receive the following error. The process cannot ...
elina's user avatar
  • 441
0 votes
1 answer
485 views

Null SPFile reference when trying to check whether a list item is checked out [duplicate]

I am trying to show an error when a user performs an operation with a list item that is checked out. How I get the list item: var listItem = list.GetItemById(itemId); This works and I can perform ...
user avatar
0 votes
1 answer
1k views

How to checkin SPCheckedOutFile

In Powershell i get all checked out file from a library with foreach($f in $lib.CheckedOutFiles){ //I tried to retrieve item with $item = $lib.GetItemById($f.ListItemID)//exception item not ...
user1898765's user avatar
1 vote
2 answers
428 views

SharePoint Online RER, how to access properties of a Microsoft.sharepoint.client.file?

I have a ItemAdded remote event receiver for a document library in the host web. Event receiver works fine. However I would like to access the properties of the file object. (Would like to see the ...
ShanVeer's user avatar
1 vote
0 answers
54 views

Timezone issues and file size differing for spfilezilla

I've uploaded some files from a local server to the Office 365 sharepoint cloud using spfilezilla. However I notice the times are different by the same offset of a few hours. Would this be a timezone ...
Darryn Brisdaz's user avatar
1 vote
1 answer
3k views

Error : The file has been modified by SHAREPOINT/system

I am creating .docx file using template of SharePoint Library and uploading it to the library. But I am facing an error while CheckOut(). Below is my code. public void UpdateAndCreateFile(SPWeb web) {...
DRS's user avatar
  • 722
1 vote
1 answer
294 views

Add SPListItem with file

I have a library, that have items and each item has additional File field. I can upload them programmicaly - firsly file is uploaded, then empty item is updated with other info. Example of filled ...
Alex Zhukovskiy's user avatar
0 votes
1 answer
717 views

How to set read-only attribute on file

I have .docx file on sharepoint which should be read only but I do not know how to set this attribute in my sharepoint application in c# code behind. How to set read-only attribute on file in code ...
ElConrado's user avatar
  • 101
1 vote
1 answer
69 views

How can I move ONE document to another library without looping an entire collection?

Currently I'm looping through all the files in a collection, which is every single document in the library. Once I find the unique document name, I move it. I'm trying to getting away from looping ...
jpollar's user avatar
  • 1,107
0 votes
1 answer
469 views

How do you get the ID of a file moved to another library?

I'm probably not doing the move the most efficient way for starters, because I'm only moving one file...not a group of files. I'd rather not have to loop through the library to find the file i want to ...
jpollar's user avatar
  • 1,107
6 votes
2 answers
2k views

Can we unlock a ShortTerm lock via CSOM for SP2013

We are using SP2013 with OWA installed. Users often complain about a file stored in SharePiont being locked by another user not in office. Error is "The file "xxxx" is locked for exclusive use by ...
Mark L's user avatar
  • 4,075
3 votes
1 answer
763 views

Files moved with SPFile.MoveTo require a full crawl to be searchable

We've got a problem in our search-driven document management system, and I'm running out of ideas. A custom event receiver, on ItemUpdated() checks to see if the files metadata requires it to be ...
Tyr's user avatar
  • 180
1 vote
1 answer
39 views

Changing to Fields with using SystemUpdate()

I'm trying to update some fields on SPListItem but i want to prevent Modified Date/ModifiedBy fields also don't want new version. So SystemUpdate(false) is used for my case but it can not prevent that ...
Onur Tolgahan Pamuk's user avatar
0 votes
2 answers
2k views

Unable to cast object of type 'Microsoft.SharePoint.SPListItem' to type 'Microsoft.SharePoint.SPFile

In code below, at mentioned line I am getting this error: How I fix this? SPList docLib = WSweb.GetList(WSweb.ServerRelativeUrl + "/Documents"); //SPList docLib = WSweb.Lists.TryGetList("Documents"); ...
SPBeginer's user avatar
  • 2,559
0 votes
1 answer
374 views

User with contributor permissions is getting access denied on SPFileCollection.Add

I faced with weird issue. I'm trying to add a new file to the library on button click event, everything is fine when site admin performs this action, but user with contributor permissions is getting ...
Topa3b's user avatar
  • 21
2 votes
2 answers
3k views

Is there a way to move a file without changing its "Modified" field?

Simple question. Is there a way to move a file without changing its "Modified" date field? I'm using SPfile.MoveTo to move the files around, and I wanted to move them in a way that it wouldn't count ...
smith's user avatar
  • 55
1 vote
1 answer
1k 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 : " + file.Item["Created"].ToString()...
smith's user avatar
  • 55
2 votes
2 answers
1k 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 /_api/web/...
Joe.wang's user avatar
  • 407
3 votes
0 answers
2k 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 /_layouts/...
Sam Larko's user avatar
  • 146
0 votes
2 answers
446 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 ...
Medes's user avatar
  • 2,086
1 vote
1 answer
3k 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 ...
user13186's user avatar
  • 886
4 votes
2 answers
2k 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 ...
ChiliYago's user avatar
  • 2,166
1 vote
1 answer
3k 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: ...
Paul's user avatar
  • 21
0 votes
2 answers
1k 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 ...
users1100's user avatar
  • 3,230
0 votes
1 answer
266 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?
iambriansreed's user avatar
6 votes
1 answer
8k 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 ...
Donald Dunlop's user avatar
1 vote
1 answer
961 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 ...
RJ Cuthbertson's user avatar
0 votes
1 answer
530 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 ...
Nacht's user avatar
  • 1,221
2 votes
1 answer
299 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 web....
Müslüm ÖZTÜRK's user avatar
1 vote
2 answers
4k 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 ...
MikeC's user avatar
  • 1,112
2 votes
1 answer
16k 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) { ...
Glolita's user avatar
  • 419
0 votes
2 answers
1k 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 ...
fallout's user avatar
  • 1,025
1 vote
2 answers
9k 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 ...
Thomas's user avatar
  • 980
1 vote
1 answer
5k 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 ...
user avatar
1 vote
3 answers
14k 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: SPContext.Current.Web....
MikeC's user avatar
  • 1,112
2 votes
1 answer
3k 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; ...
Abe Miessler's user avatar
  • 6,755
0 votes
1 answer
553 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 ...
sq33G's user avatar
  • 101
2 votes
0 answers
490 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 ...
OneFreeFitz's user avatar
0 votes
1 answer
2k 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 ...
user1038560's user avatar
1 vote
1 answer
2k views

Programmaticly updating SPFileVersion.Properties Hashtable

Anyone who has experience with programmatically 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 ...
Frederik P.'s user avatar
3 votes
3 answers
5k 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 FileInfo(...
Tschareck's user avatar
  • 2,155
0 votes
1 answer
2k 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. ...
matt137's user avatar
  • 141
6 votes
2 answers
3k 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 present ...
Natan's user avatar
  • 240
0 votes
1 answer
1k 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 ...
QMKevin's user avatar
  • 1,252
1 vote
1 answer
3k 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() }
Robert G's user avatar
  • 187
5 votes
3 answers
640 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 ...
Jaap Vossers's user avatar
  • 5,030
0 votes
1 answer
455 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 ...
Colin's user avatar
  • 4,655
28 votes
3 answers
16k 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 137DA01F-...
Iunknown's user avatar
  • 547