Earlier I have posted the post showing the parsers that are available in the SharePoint. In this post I will show how to associate a file type with the SharePoint default parsers. This can be helpful if anyone wants to parse the file with its own extension but want to use the default parser. In this I have created a document parser object and added that object to the Pluggable Parser set available to the Web Service.
CODE SIPPET
namespace
ParserExample
{
class Program
{
static void Main(string[]
args)
{
#region Custom
Extension Association
//getting
the Plugable Parsers
SPWebService
objService = SPWebService.ContentService;
Dictionary<string, SPDocumentParser>
parser =
objService.PluggableParsers;
//Creating
a custom parser
string
extension = "txt";
string
progID = parser["docx"].ProgId;
SPDocumentParser
customParser = new SPDocumentParser(progID,
extension);
//Removing
the parser if already exists
if
(parser.ContainsKey(extension))
{
parser.Remove(extension);
objService.Update();
}
//Adding
the custom parser to the pluggable parser collection
objService.PluggableParsers.Add(extension, customParser);
objService.Update();
#endregion
}
}
}
Output
No comments:
Post a Comment