Skip to content

Instantly share code, notes, and snippets.

@Vintaurus
Created December 27, 2017 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vintaurus/72548a19c313cd5201b218c3a5c3ffbf to your computer and use it in GitHub Desktop.
Save Vintaurus/72548a19c313cd5201b218c3a5c3ffbf to your computer and use it in GitHub Desktop.
string directoryDatasetFile = "D:\upload\Report_Dataset.rsd";
string datasetFileName = Path.GetFileName(datasetFile);
string datasetFullUrl = string.Concat("http://sharepoint/dashboard/Data Connections/Datasets/", datasetFileName)
SPFolder folder = ....; //get folder "Datasets" from library "Data Connections"
using(FileStream fileStream = File.OpenRead(directoryDatasetFile))
{
folder.Files.Add(datasetFileName, fileStream, true);
}
//Add DataSource
DataSourceReference reference = new DataSourceReference();
reference.Reference = dataSourcesFileFullUrl;
//if you have different datasource files for some reports, so you can get
//information directly from dataset file
/**
XmlDocument xDocument = new XmlDocment();
using(FileStream stream = File.OpenRead(directorySourceFile))
{
xDocument.Load(stream)
}
XmlNamespaceManager namespaces = new XmlNamespaceManager(xDocument.NameTable);
namespaces.AddNamespace("sdsd", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/shareddatasetdefinition");
XmlElement root = xDocument.DocumentElement;
XmlNode dataSourceReferenceNode = root.SelectSingleNode("sdsd:DataSet/sdsd:Query/sdsd:DataSourceReference", namespaces);
string dataSourceFileName = dataSourceReferenceNode.InnerText;
**/
DataSource[] itemDataSources = reportingService.GetItemDataSources(datasetFullUrl);
DataSource dataSource = new DataSource();
dataSource = itemDataSource[0];
dataSource.Item = reference;
reportingService.SetItemDataSources(datasetFullUrl, itemDataSources);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment