Create folder in document library using SharePoint workflow - c#

I want to create folder inside my document library based on other document library in the root. And I want to run this workflow on new document library creation.
So let say I have 4 document library:
Help
News
Doc
Archive
I want to create folder inside "Archive" Document library when New document library is created.
Help
News
Doc
Archive
New Doc Library
and in Archive document library it will create folders
Help
News
Doc
New Doc Library
Is it possible..?
How can I do it.??
--
Thanks in advance.

string archiveListUrl = "http://myserver/Archive/";
SPSite site;
SPWeb web;
SPDocumentLibrary library;
using (site = new SPSite(archiveListUrl))
using (web = site.OpenWeb())
{
library = (SPDocumentLibrary)web.Lists["Archive"];
web.Folders.Add(archiveListUrl + "Help");
web.Folders.Add(archiveListUrl + "News");
web.Folders.Add(archiveListUrl + "Doc");
web.Folders.Add(archiveListUrl + "New Doc Library");
library.Update();
}

Thats difficult: Workflows are are always attached to one document/item. One thing you could do: Create the Library from a customized template - and you can customize this lib with an workflow to start on creation of a doc. Then add a document to the library and save the whole thing as template with content.
(Actually you might check if creating a lib template with existing folders might be easier...)

Related

Getting files from Sharepoint using .Net

Good afternoon, I am using the Microsoft.SharePointOnline.CSOM library to work with Sharepoint. I have a code where I get a list called MyDoc like this:
using (var context = new ClientContext(url)
{
varweb = context.Web;
var list = web.Lists.GetByTitle("MyDocs");
}
Then I iterate through all the folders to find a folder with a suitable name and get files from there. With the help of file.ServerRelativeUrl I found out the link to the file on Sharepoint:
/MyDocs/Documents/Students/Homework/1lesson.pdf
How can I immediately access the Homework folder and download all the files from there without going through all the possible folders in the MyDocs sheet?
Instead of getting the list, just use the method GetFolderByServerRelativeUrl within the context.Web object
var folder = context.Web.GetFolderByServerRelativeUrl("/MyList/MyFolder");
context.Load(folder);
context.ExecuteQuery();

Duplicate Word Document Using OpenXML While Open Original Document

I need to create a same copy of existing word document and open it as another instance while the original first document being opened. The second word document do not save but user may have the option to save it or not.
This need to be done using OpenXML.
I will attached here the current implementation. This implementation is having several issues.
The first document need to close first before use it in WordprocessingDocument using statement.
The second newly created document need to save in local folder.
Code Initiation
var doc = Globals.ThisAddIn.Application.ActiveDocument;
doc.Save();
string fileName = doc.FullName;
doc.Close();
using (WordprocessingDocument document = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
{
}
Why do you need to use OpenXML ? With Interop you could simply:
Open the existing document
Copy everything within the document range
Create a new document
Paste the other document in the new one
It's done quickly and does the job perfectly

Store BuildingBlocks in word document via Aspose

I'm looking for an example to store building blocks in a word document with the Aspose Word Api. And I want to use these building blocks exclusiv in this document.
Has anybody an idea, how this can be realized?
Greetings
Tobi.
If you have MS Word 2013 installed on your machine, you'll most likely find a Word document 'Built-In Building Blocks.dotx' at the following location:
C:\Users\Awais\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Built-In Building Blocks.dotx
The predefined built-in building blocks entries that ship with Word are stored in above template document. Using Aspose.Words, you can extract any building block from it, paste inside another Word document and save new document for future use.
GlossaryDocument class in Aspose.Words represents such Building Blocks. Please try using the following code:
Document docBuildingBlocks = new Document(MyDir + #"Building Blocks.dotx");
Document doc = new Document(MyDir + #"input.docx");
GlossaryDocument glossaryDocument = docBuildingBlocks.GlossaryDocument;
foreach (BuildingBlock buildingBlock in glossaryDocument.BuildingBlocks)
{
if (buildingBlock.Gallery.ToString().StartsWith("CoverPage"))
{
Section sec = (Section)buildingBlock.FirstChild;
doc.AppendChild(doc.ImportNode(sec, true));
}
}
doc.Save(MyDir + #"15.6.0.docx");
Hope, this helps.
I work with Aspose as Developer Evangelist.

Save PPS/PPT files as SWF using C#

I want to build a C# application that save a pps\ppt file as SWF.
For saving pps\ppt as image I use this code:
Application apps = new Application();
Presentations pps = apps.Presentations;
foreach (string file in Directory.GetFiles("[here is a path]", "*.ppt"))
{
try
{
Presentation p = pps.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
p.SaveAs("[here is a path]" + p.Name, PpSaveAsFileType.ppSaveAsJPG); //It saves the slides as images in a folder.
Console.WriteLine(id.ToString() + ". " + p.Name);
p.Close();
id++;
}
catch{ }
}
So, how can I save the pps\ppt files from a folder as SWF?
There isn't this: PpSaveAsFileType.ppSaveAsSWF
No you can't using PowerPoint API.
To convert PowerPoint files to Flash you have look for software vendors that sell specific API to do that.
Anyway, not all PowerPoint objects/features are supported so you could lose some kind of contents.
Of course it can be done if you develop an application by your self but you need strong knoledge of PowerPoint API and Flash accessing pptx (openxml) files from Flash... it's a job.
You need to convert PPT files with some third-party software that has a C# API. I use print2flash for this purpose. The core conversion code I use is quite simple if I omit some options from my real C# application
Print2Flash4.Server2 serv = new Print2Flash4.Server2();
Print2Flash4.Profile2 prof = new Print2Flash4.Profile2();
prof.DocumentType = Print2Flash4.DOCUMENT_TYPE.FLASH;
serv.ConvertFile(inputfile, swf_file, prof, null, null);
To use this code, you need to get Interop.Print2Flash4.dll as well. You may get the dll and further instructions from the sdk available for download from http://print2flash.com/download.php

How to create a component by providing the XML source file as input

I want to create a component by giving XML source input directly using core service 2011, in SDL Tridion 2011.
I want to write code to create a component by uploading source XML. Using the core service 2011.
Say name of the xml file is helloworld.xml and location is D:\abcd\cdef\all\helloworld.xml.
I have written the code like this, but its not working.
XmlDocument contentxml = new XmlDocument();
contentxml.LoadXml(#"D:\abcd\cdef\all\helloworld.xml");
Response.Write("<BR>" + contentxml.ToString());
component.Content = contentxml.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
The Response.write is displaying nothing. Correct me if I missed any thing.
It's not creating any component and error is coming.
When i tried this:
XmlDocument contentxml = new XmlDocument();
try
{
contentxml.LoadXml(#"D:\abcd\cdef\all\helloworld.xml");
}
catch (XmlException exp)
{
Console.WriteLine(exp.Message);
}
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
contentxml.WriteTo(xw);
Response.Write("<BR>" + sw.ToString());
component.Content = sw.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
This time it's showing unable to find UUId: some thing like that.
My helloworld.xml looks like this.
<Content xmlns="uuid:1111eb85-0X11-11f9-1e2X-1X82X78fX920">
<first>Hello World.This is Fisrt field</first>
<second>Hello World.This is second field</second>
</Content>
It would be great if some one share some sample code to do it.
Loading any XML from a a file and trying to create a component won't work unless the XML uses the format the CMS is expecting.
The XML structure of a component in SDL Tridion has some fixed parts (Example Nodes Content, Metadata) plus some flexible parts
(The way you define the fields).
First you need to have the XML with the same structure that the CMS is expecting.
Typically the nodes that should be in your xml are the CONTENT and METADATA, load those in an XML Document and use the Core Service API to
create a component using the content contained in those nodes.
The best way to know how which is the structure of a component based on an schema is to create a sample component using the Tridion UI and
see how the XML is constructed. After that you need to create your XML Sources using that structure.
I posted recently an example of how to create a component using the Core Service, please have a look at that.
Faulted State error while creating component with Core Service
Following this code, you can access the nodes Content and Metadata
componentData.Content = xmlUtil.GetNewXmlNode("Content", schemaData.NamespaceUri);
componentData.Metadata = xmlUtil.GetNewXmlNode("Metadata", schemaData.NamespaceUri);
And replace those with your content
The general outline:
Load the XML from the file into an XDocument / XmlDocument.
Create a new Component by calling GetDefaultData on the client.
Set the Content property of the Component to the XML.
Save the Component by calling Save on the client.
If you haven't already, please have a look at the Core Service API documentation available on SDL Tridion World.
If you have trouble implementing this, please post the code that you have and what you have tried in order to make it work.
Using XmlDocument.LoadXML() expects an XML string as input, as commented by Peter you should use XMLDocument.Load() instead, see here for more details http://msdn.microsoft.com/en-us/library/a8ta6tz4.aspx
When you have passed that hurdle you will need the information Miguel gave in his answer to continue.

Categories