Automatically add tag to uploaded document in sharepoint - file-upload

My environment is sharepoint 2010 and vs 2010.
I already have an OOTB document library that I am using and I wanted to know how I can add a tag or keyword to a METADATA column.
I am using the same document library in all subsites and so would like to tag the uploaded document with the name of the current site (ie if it's being used in a subsite, that subsite's name would be the tag).
Would I need to build a custom document library or some sort of add-on webpart that attaches to the existing document library?
If you could provide some code samples if any that would be appreciated.
thanks,
KS

If you are starting from scratch you can create a custom content type based on the build in content type Document (a child content type of Document). Add a custom field to your content type. For more information regarding creating content types look here: http://msdn.microsoft.com/en-us/library/gg295290.aspx
A content type can also have a custom event receiver for ItemAdding, ItemUpdated etc. Look at the xml below:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x010100xxxxxx"
Name="MyContentType"
Group="My custom group" Version="0" Inherits="True" Overwrite="TRUE" >
<FieldRefs>
<FieldRef ID="{AC8A823D-EB2F-4D4D-8BF0-14CACA509539}" Name="myMetadataField" Required="FALSE" />
</FieldRefs>
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events">
<spe:Receivers xmlns:spe="http://schemas.microsoft.com/sharepoint/events">
<Receiver>
<SequenceNumber>1010</SequenceNumber>
<Name>HandoverOffshore_ItemAddedReceiver</Name>
<Type>ItemAdded</Type>
<Assembly>MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=79315a88caec227a</Assembly>
<Class>MyAssembly.CustomEventReceivers</Class>
</Receiver>
</spe:Receivers>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>
Then you'll have to create the event receiver class witch handles the custom event:
public class HandoverOffshoreEventReceivers : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
// your code for updating metadata field here...
}
}
Then you deploy this to your site collection and add this content type to all your libraries. Also set this as the default content type in all libraries.
If you are creating many libraries you should consider to create a custom library definition based on this content type.
If you want this custom event fired for existing documents you'll have to change their content type to the new one you created here.
Note that document library content types are child content types of the site collection content types.

Related

Using an Alfresco Share Form Page, How do I upload a new file with metadata?

I'm working With Alfresco Community Edition.
Here's the code I've tried so far: Alfresco-Smalgyax.
I have created an All-in-One Project, to add a new page to the create.. menu. My Page Loads just fine.
I followed, the Adding a menu item to the "Create..." menu in DocLib tutorial, before adding a custom form field and JavaScript to the newly added share page.
I've added a custom field to upload a file to cm:content.
I've added some Javascript to get and set the cm:name and mimetype once an Upload file is chosen.
All the Metadata is correctly ingested. However, the file is not.
Previously I was successfully, able to upload a file with custom data by following the documentation: Processing multipart forms. However, that created a whole new Service endpoint and a custom page that didn't inherit the same look/feel as the rest of the web-application.
The page under create.. has the same look/feel as the rest of the site. But Upload Fails, Is there a way to leverage the Look/feel of the site and upload a file with metadata and set a custom type in Alfresco?
Clarification
The cm:content field has been customized like so:
<field id="cm:content" label-id="" mandatory="true">
<constraint-handlers>
<constraint type="MANDATORY" event="input"
validation-handler="Smalgyax.forms.validation.setNameValue" />
</constraint-handlers>
<control template="/file.ftl">
<control-param name="editorAppearance">explorer</control-param>
</control>
</field>
file.ftl sets the form input element like so:
<input id="${fieldHtmlId}" type="file"
name="${field.name}"
<#if field.disabled>disabled="true"</#if> />
additionally, file.ftl adds custom JavaScript to the page, because I was unable to get it successfully loaded as a separate file using
<forms>
<dependencies>
<js src="/set-name-field.js"/>
</dependencies>
<!-- form definition here -->
As the Alfresco documentation clearly suggests it won't supports the upload feature. The field type shows cm:content that won't accept a file to accept a file even though you have customized and added a explorer option in the code. That is the reason file is not and only content is uploading.
https://docs.alfresco.com/community/tasks/dev-extensions-share-tutorials-add-menuitem-create-menu.html
<field id="cm:content" label-id="">
<control>
<control-param name="editorAppearance">explorer</control-param>
</control>
</field>
For upload a file , you should use the html component like below,
<input type="file" multiple="" name="files[]" class="dnd-file-selection-button">
and the javascript should be same as the file-upload.js and dnd-upload.js.
http://localhost:8180/share/res/components/upload/file-upload.js
http://localhost:8180/share/res/components/upload/dnd-upload.js
Please refer the link below to upload a file through a ajax call.
https://hub.alfresco.com/t5/alfresco-content-services-forum/how-to-upload-a-file-from-a-custom-share-page/td-p/32361

Sensenet: Define Content Type with File Upload

How Can I define an content type with a field that contains an file? I think I should use binary type data to do it that but I don't know how to do the rest...
This example uses image upload, but I'm don't know how to define a field as a simple file upload...
The "File" content type is designed to upload any kind of file. In the example - what you said - described a specialized content type with image related metadata. You should try to use the File content type. If its metadata is not good enough for you, you can create an inherited content type with the desired field set.
As Zoltan has written in sensenet there is a predefined content type called File to handle any kind of file you want. If you inherit your custom CTD from this type (parentType="File") it will automatically have a Binary field to store file's binary data when upload and you can define additional fields for custom metas.
If you want to use a content type inherited differently you can use a Binary field to store any kind of data, but will lose built in upload functionality (Upload page). In the other hand on the New/Edit page there will be the File upload's Browse button beside your custom field.
With this it's important to set properly the visibility configurations. If it's set to Hide then you won't be able to upload a file from the New or Edit page.
<Field name="CustomField" type="Binary">
<DisplayName>Custom Field</DisplayName>
<Configuration>
<VisibleBrowse>Hide</VisibleBrowse>
<VisibleEdit>Show</VisibleEdit>
<VisibleNew>Show</VisibleNew>
</Configuration>
</Field>

Getting HTML of Smart Form Content in Ektron

I am working in Ektron 8.0.
I have created a smart form configuration in Settings,I assigned this particular smart form configuration for
a Folder and created a Smart form content.Now i am trying to access the Smart Form content programmatically.
I am getting the "XML" data as the content.Html property.Is there is any way i can get the HTML data corresponding to a smartform content,rather than these XML data?
There are a few ways to this, here are two.
XSLT:
<CMS:ContentBlock runat="server" Visible="true" DisplayXslt="/xmlfiles/SmartForm.xslt" DefaultContentID="23" />
The SmartForm.xslt file translates the xml into formatted html.
Use XSD to access SmartForm Content on the code behind.
This article explains the process.
http://developer.ektron.com/Templates/KBDetail.aspx?id=603
You need to get a copy of the .xsd file and use it to create an object definition for your smart form.
Use the xsd.exe tool to create a class. The command looks like this.
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\xsd.exe" "C:\inetpub\site\xsd\SmartFormContet.xsd" /classes /language:CS /namespace:SmartForm.SmartFormContent
This will generate a class file named SmartFormContet.cs
Copy this file and paste into the code behind of the page.
Deserialize the XML from the Content.Html property.

Create Folders in Library when submitting a list form in SharePoint 2010

I would like to know if it's possible to create folders when submitting a form in SharePoint. I created a custom SharePoint list form in Infopath and I want to add an action to the submit button to create four folders, one for each of the four doc libraries, that contains the title of the submitted item.
I see however that the custom code button is not enabled for a SharePoint list in Infopath so I cannot add any code in the background. The workflows that come out of the box also does not allow me to do it, unless I'm missing something...What other way is there to do it?
Thanks in advance for any help!!
Yes you can do this, however, it's quite tricky.
In theory, you could call the "UpdateListItems" method of the Lists.asmx web service and pass a batch statement but due the implementation of the Lists web service you cannot use it in InfoPath. That's why you need to write your own web service that wraps the UpdateListItems method so you can use it with IP.
If you do not know how to write a web service (and host it within SharePoint) please use the search function of StackOverflow or consider google - many great tutorials out there ;-)
Once you got the web service running, you need to add a service reference to the http://myserver/_vti_bin/Lists.asmx web service and then create the following method:
[WebMethod]
public void UpdateListItems(string listGuid, string xmlBatch)
{
var batch = new XmlDocument();
batch.LoadXml(xmlBatch);
//create an instance of the lists proxy client
var listSvc = listService = new ListsWebService.Lists();
//set the url of the client
listService.Url = "http://myserver/_vti_bin/Lists.asmx";
listSvc.UpdateListItems(listGuid, batch);
}
Note that if you configure the listSvc's Url hardcoded (like in this example), you need to make sure that the List, you want to add the folders to, is within the same site as the Url. If you want to make it this method more generic (which i'd suggest you do), you could simply pass the SiteCollection Url as a parameter and set listSvc.Url to SiteCollectionUrl + "_vti_bin/Lists.asmx".
Once this is set up, you can create the data connection to your newly created web service in InfoPath and configure it like this:
The field "listName" is actually the GUID of the List - you can get it via the UI by clicking "Library Settings" - "Information management policy settings" and then copy it from the address bar in your browser. Example:
{39d01277-4ba1-4589-90f8-c957b4b2dd09}
The field "XML" contains the batch script to create the folder. You can declare it staticly, or in your case, you can build it dynamically using the concat() function. This example creates a folder named "MyFolder" in the root of the Library.
<Batch>
<Method ID='1' Cmd='New'>
<Field Name='ID'>New</Field>
<Field Name='FSObjType'>1</Field>
<Field Name='BaseName'>MyFolder</Field>
</Method>
</Batch>
If you need to have sub-folders, this is possible too. This following example will create a folder named "MySubFolder" within the folder "MyFolder".
<Batch>
<Method ID='1' Cmd='New'>
<Field Name='ID'>New</Field>
<Field Name='FSObjType'>1</Field>
<Field Name='BaseName'>MyFolder/MySubFolder</Field>
</Method>
</Batch>
Then you simply add a submit button action and you're done :-)
Also note that the code above is just an example (which works though). If you use it in production be sure to add proper exception logging because you'll be needing it :-)
hope this helps!

Change the Category for Web Part to be displayed

In Sharepoint 2010, is there any way to change the category where custom web parts created in VS2010 to be placed.
VS2010 is putting the custom web part in "Custom" category by default. I'm curious that, is there any way for us to change it, for example "MyCustomWebParts" category.
incase I couldn't made myself clear:
You can change file Elements.xml. Into File tag add line:
<Property Name="Group" Value="MyCustomWebPart" />
or
Select “Site Actions” >> “Site Settings” >> “Modify All Site Settings”.
Click the “Web Parts” link in the Galleries group.
Open your webpart for edit.
In the Group section, check the “Specify your own value” option and type in a group name (e.g. MyCustomWebParts)
There is! In the .webpart file, under the Module/File path, add a tag like this:
<Property Name="Group" Value="My Custom Group"/>
That's all there is to it!