I need to add new version of the file to SPFileCollection without changing version (it is a system update of the content of pdf file)
UpdateOverwriteVersion allows me to change metadata but is there a way to change content (bytes) of the file?
WORKAROUND:
Ok, as Stefan found out, there is no satisfactory solution to this.
I found two workarounds:
1.
(Be aware that turning off the version control could lead to wrong behavior, if there are people working on that list... – Stefan)
oFile = oWeb.GetFile(url);
oFile.Item.ListItems.List.EnableVersioning = false;
oFile.Item.ListItems.List.Update();
oFolder.Files.Add(oFile.Name, aBytes, fileProperties, true);
oFile.Item.ListItems.List.EnableVersioning = true;
oFile.Item.ListItems.List.Update();
2.
oFile = oWeb.GetFile(sAdres);
int iFileVersion = oFile.UIVersion;
oFolder.Files.Add(oFile.Name, aBytes, fileProperties, true);
oFileVersion = oFile.Versions.GetVersionFromID(iFileVersion);
if (null != oFileVersion && !oFileVersion.IsCurrentVersion)
{
oFileVersion.Delete();
}
Why don't you use SystemUpdate(false)
http://msdn.microsoft.com/en-us/library/ms481195.aspx
You can load the SPFile object and then call SPFile.SaveBinary(Stream, SPFileSaveBinaryParameters) method to update it's content.
With the CreateVersion property of the SFileSaveBinaryParameters you can specify whether a new version should be created or not.
[...] this is by design. As far as I know , there is no other solutions on it.
A quote from a moderator at Microsoft TechNet forum.
Related
Looked at this question which seems to address my need.
I need the VB.net (2015 preferred) syntax for this snippet. Specifically, Assign the TokenLifespan line.
if (dataProtectionProvider != null)
{
manager.UserTokenProvider =
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"))
{
// Added custom code to set a different lifespan
TokenLifespan = TimeSpan.FromHours(3)
};
}
Well, I have looked a day and never did find an answer to my C# to VB syntax question. No 'freely available online converter' was able handle the snippet. I tried perhaps a dozen or more. The ones that didn't error, skipped the property assignment.
In the end, I managed to code around the unknown syntax by instantiating an object and then assigning the property.
Here is the code I used to set the DataProtectorTokenProvider.TokenLifespan value:
If dataProtectionProvider IsNot Nothing Then
Dim oTokenProvider As Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider(Of ApplicationUser)
oTokenProvider = New DataProtectorTokenProvider(Of ApplicationUser)(dataProtectionProvider.Create("ASP.NET Identity"))
oTokenProvider.TokenLifespan = TimeSpan.FromMinutes(15)
manager.UserTokenProvider = oTokenProvider
End If
Perhaps this will help someone else down the road.
:-)
Today, I'm having a problem is after I had created a Calculated field. It seems there is no way to add AllContentTypes. And the DefaultView, maybe I can handle this. And I also saw this method:
spList.Fields.AddFieldAsXml(spFieldUser.SchemaXml, True, SPAddFieldOptions.AddToAllContentTypes);
But in this case, I'm not sure I can use it or not. Because my code is:
//SPField tempSPField = spList.Fields.CreateNewField(createSPColumnObject.ColumnType, createSPColumnObject.ColumnName);//We can not use this code line for creating Calculated (there is no constructor for this)
SPFieldCollection collFields = spList.Fields;
string strSPFieldCalculatedName = collFields.Add(createSPColumnObject.ColumnName, SPFieldType.Calculated, false);
if (createSPColumnObject.IsAddedToDefaultView)
{
SPView spView = spList.DefaultView;
spView.ViewFields.Add(strSPFieldCalculatedName);
spView.Update();
}
SPFieldCalculated spFieldCalculated = null;
//
spFieldCalculated = (SPFieldCalculated)collFields[createSPColumnObject.ColumnName];
spFieldCalculated.ShowInDisplayForm = true;
//spFieldCalculated.ShowInEditForm = true;
spFieldCalculated.ShowInListSettings = true;
//spFieldCalculated.ShowInNewForm = true;
spFieldCalculated.ShowInViewForms = true;
//
spFieldCalculated.Description = createSPColumnObject.ColumnDescription;
spFieldCalculated.Formula = string.Format(#"={0}",createSPColumnObject.CalcFormula);
spFieldCalculated.Update();
//spList.Fields.AddFieldAsXml(spFieldCalculated.SchemaXml, createSPColumnObject.IsAddedToDefaultView, SPAddFieldOptions.AddToAllContentTypes);// also use this code line because we will get an exception with a duplicate column ID.
spFieldCalculated.OutputType = SPFieldType.Text;
spList.Update();
I totally created a Calculated column but how can I add it to allcontent types ? everybody could help me out this ? BTW, to the DefaultView, I did like the above is right ? Could eveybody let me know this ?
I just worry about everybody get misunderstanding ? Or review with missing code. So could everybody please to take a look on my code clearly ? Thanks all.
Many thanks, :)
Standley Nguyen
I'm not sure if i fully understand what you are trying to do however i may be able to shed some light on some parts of what you are trying to do.
When you create your field does it then appear in your site actions -> site settings -> Site columns. If so you have created this correctly. If it doesn't there are hundreds of examples of how to do this if you search google.
Once you have your field create you then need to consider which content types you want to add it to. Once you have these content types you then have to add something called a field link to the Content type.
This isn't my code i have picked it off the web but this should do what you require.
SPContentType ct = web.ContentTypes[contentType];
ct.FieldLinks.Add(new SPFieldLink(field));
ct.Update();
Cheers
Truez
I am trying to create a "label" with different styles on different words, kind of like described here.
The problem is - as far as I can see - the MonoTouch implementation of UATextLayer does not accept assigning an NSAttributedString to the String property since the String property has the type string.
Is this an error in the implementation or is there another way of doing this?
(Yes, I am aware I can add separate labels - but I would rather not when there is a better solution).
EDIT (in response to the answer from Miguel):
After changing to GetHandler and correcting to "void_objc_msgSend_IntPtr" instead of "void_objc_msgSend_IntPrt" the code in the answer compiles and runs, but it doesn't quite work anyway (I was a bit fast in marking it as the answer).
No errors are thrown, but the text doesn't show.
Code:
string _text="Example string";
if(_textLayer==null) {
_textLayer = new CATextLayer();
_textLayer.Frame = new RectangleF(50,698,774,50);
_textLayer.Wrapped=true;
_textLayer.ForegroundColor=UIColor.White.CGColor;
_textLayer.BackgroundColor=UIColor.Clear.CGColor;
Layer.AddSublayer(_textLayer);
}
//_textLayer.String=_text;
CTFont _font=new CTFont("MarkerFelt-Thin",48);
CTStringAttributes _attrs=new CTStringAttributes();
_attrs.Font=_font;
_attrs.ForegroundColor = UIColor.White.CGColor;
var nsa = new NSAttributedString(_text);
Messaging.void_objc_msgSend_IntPtr(
_textLayer.Handle,
Selector.GetHandle("string"),
nsa.Handle);
If I uncomment the _textLayer.String=_text I see the text (but without attributes of course), so the problem is not with the layer.
For now, you can try:
using MonoTouch.ObjCRuntime;
var caTextLayer = new CATextLayer ();
var nsa = new NSAttributedString ();
[..]
Messaging.void_objc_msgSend_IntPrt (
caTextLayer.Handle,
Selector.sel_registerName ("string"),
nsa.Handle);
Alternatively, can you download this preview of the upcoming version:
http://tirania.org/tmp/monotouch.dll
It implements a property AttributedString in CATextLayer that you can set.
I'm creating a Sharepoint feature, this feature has an event receiver associated to it. In the event receiver, I'm creating a Document Library and Picture Library using server-side object model. I'm also adding new custom columns (around 80) to these newly created document and picture library. Now I want to modify the properties of the Description, Keywords and Title fields that are by default created along with the picture library. I want to make these fields as Required fields. How do I do this? I tried to set SPList.AllowContentTypes = true and try to change the attributes of these fields, but it doesn't work (neither gives an error nor makes these required fields). I also tried to access the content types and try to change the attributes using SPContentType.FieldsLinks["Column_name"].Required and SPContentType.Fields["Column_name"].Required but it gives me an error. Does anyone have any other suggestions?
Here is the answer....
SPContentType ct = mypiclib.ContentTypes["Picture"];
SPFieldLinks titleLink = ct.FieldLinks["Title"];
SPFieldLinks descLink = ct.FieldLinks["comments"]; //internal name of Description
SPFieldLinks keywords = ct.FieldLinks["keywords"];
titlelink.Required = true;
descLink.Required = true;
keywords.Required = true;
ct.Update();
can you tell us the error you got when trying to use the fieldlinks? Because this should work... I have done it like this:
SPContentType ct = web.Lists["*ListName*"].ContentTypes["*ContentTypeName*"];
SPFieldLinkCollection flinks = ct.FieldLinks;
flinks["*ColumnName*"].Required = true;
ct.update();
This should do the trick:
SPWeb yourWeb = ... //assign your web
SPList yourPictureLibrary = ... //assign your picture library
web.AllowUnsafeUpdates = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Title].Required = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Description].Required = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Keywords].Required = true;
yourPictureLibrary.Update();
SPAllowContentTypes isn't settable. You might try setting ContentTypesEnabled instead.
I don't have a 2010 box to test against, but if SPAllowContentTypes returns false I think you're looking at modifying the definition of your picture library in the 14 hive (TEMPLATE\FEATURES\PictureLibrary\PicLib) to get what you're after. Tread lightly there.
I am accessing SharePoint via its web services... Which are a bit limited, as a result I have turned to WebDav to perform some create folder functionality...
I have a document library, and I am about to create a folder using webdav, but I can't find any documentation on the internet or anywhere else on how to check if a folder already exists using webdav, so is there a way to check if a folder exists in a document library in SharePoint, any hack and slash methods welcome!
Somehow, I don't get your question. First sentence states you are using web service (I'd normally understand it as the SOAP web services provided by SharePoint). The next one says you are using WebDAV which is a completely different protocol.
So, WebDAV is the protocol "Windows Explorer" uses to access SharePoint, if you open it it "Explorer mode". Since all these requests are actually HTTP requests, you can spy on them, using the "Fiddler" tool.
I believe, before opening a folder, Windows Explorer tries to query sharepoint, if such folder exists. If I try to open an unexistant path \\mysrv\sites\myweb\mylib\notthere (but \\mysrv\sites\myweb\mylib is an existing document library!) thru windows explorer, the last HTTP call I see is:
PROPFIND /sites/myweb/mylib HTTP/1.1
User-Agent: Microsoft-WebDAV-MiniRedir/6.1.7600
Depth: 1
translate: f
Where SharePoint responds with: a list of subfolders and pages in this folder (very long XML, but it contains items like this):
<D:multistatus
xmlns:D="DAV:"
xmlns:Office="urn:schemas-microsoft-com:office:office"
xmlns:Repl="http://schemas.microsoft.com/repl/"
xmlns:Z="urn:schemas-microsoft-com:">
<D:response>
<D:href>http://sites/myweb/mylib</D:href>
<D:propstat>
<D:prop>
<D:displayname>mylib</D:displayname>
<D:lockdiscovery/>
<D:supportedlock/>
<D:isFolder>t</D:isFolder>
<D:iscollection>1</D:iscollection>
<D:ishidden>0</D:ishidden>
<D:getcontenttype>application/octet-stream</D:getcontenttype>
<D:getcontentlength>0</D:getcontentlength>
<D:resourcetype>
<D:collection/>
</D:resourcetype>
<Repl:authoritative-directory>t</Repl:authoritative-directory>
<D:getlastmodified>2009-12-07T09:07:19Z</D:getlastmodified>
<D:creationdate>2009-11-06T13:30:26Z</D:creationdate>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
<!---List of other <D:response> elements -->
</D:multistatus>
If the contained element is a folder, it must have "D:isFolder" value "t". This way you can find, if the parent folder contains the folder you are going to create.
EDIT: created a small c# sample which first reads the result stream and then parses the result a bit. You need to make it better, to see if the list contains the folders you need or not.
System.Net.HttpWebRequest oReq;
string sUrl = "http://yoursite/sites/somesite/DocumentLibrary";
oReq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(sUrl);
oReq.Method = "PROPFIND";
oReq.Credentials = System.Net.CredentialCache.DefaultCredentials;
oReq.AllowAutoRedirect = true;
oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";
//this causes all of the items to be enumerated,
//if it is 0, only the folder itself is returned in the response
oReq.Headers["Depth"] = "1";
oReq.Headers["translate"] = "f";
System.IO.StreamWriter oRequest =
new System.IO.StreamWriter(oReq.GetRequestStream());
oRequest.WriteLine();
oRequest.Close();
System.IO.StreamReader oResponse =
new System.IO.StreamReader(oReq.GetResponse().GetResponseStream());
string sResponse = oResponse.ReadToEnd();
oResponse.Close();
//done with the webclient stuff, check the results
System.Xml.XmlDocument oMyDoc = new System.Xml.XmlDocument();
oMyDoc.LoadXml(sResponse);
System.Xml.XmlNamespaceManager oNsMgr =
new System.Xml.XmlNamespaceManager(oMyDoc.NameTable);
oNsMgr.AddNamespace("D", "DAV:");
System.Xml.XmlNodeList oAllResponses =
oMyDoc.SelectNodes(".//D:multistatus/D:response", oNsMgr);
foreach (System.Xml.XmlNode oNode in oAllResponses)
{
Console.WriteLine("Name: " +
oNode.SelectSingleNode("./D:propstat/D:prop/D:displayname",
oNsMgr).InnerText);
if (oNode.SelectNodes("./D:propstat/D:prop/D:isFolder", oNsMgr).Count > 0)
{
Console.WriteLine("Is folder: " +
oNode.SelectSingleNode("./D:propstat/D:prop/D:isFolder",
oNsMgr).InnerText);
}
else
{
Console.WriteLine("Is folder: f");
}
Console.WriteLine();
}
YOu don;t need to, if it already exists, trying to create a new folder with that name will "silently" return the already existing folder.