Skip to content

Instantly share code, notes, and snippets.

@Vintaurus
Created December 27, 2017 20:41
Show Gist options
  • Save Vintaurus/fbc96a2b58b92879dc22708db962d423 to your computer and use it in GitHub Desktop.
Save Vintaurus/fbc96a2b58b92879dc22708db962d423 to your computer and use it in GitHub Desktop.
string dataConnectionsLibraryUrl = "http://sharepoint/dashboard/Data Connections/DataSources"
string directorySourceFile = "D:\upload\Reporting.SSAS.Tabular.rds";
//Need to change file extension for SharePoint
string sourceFileName = Path.GetFileName(directorySourceFile).Replace("rds", "rsds");
//Relevant for dataset property
string dataSourcesFileFullUrl = string.Concat(dataConnectionsLibraryUrl, sourceFileName);
XmlNode extensionNode = null;
XmlDocument xDocument = new XmlDocument();
using(FileStream stream = File.OpenRead(directorySourceFile))
{
xDocument.Load(stream);
}
//Get connection data
XmlNodeList connectionPropertiesNodes = xDocument.SelectNodes("RptDataSource/ConnectionProperties");
foreach(XmlNode node in connectionPropertiesNodes)
{
extensionNode = node.SelectSingleNode("Extension");
}
//Set Data Source Definition
DataSourceDefinition dsDefinition = new DataSourceDefintion();
dsDefinition.Extension = extensionNode.InnerText;
dsDefinition.Prompt = null;
dsDefinition.ConnectString = "Data Source=....;Initial Catalog=....";
dsDefinition.ImpersonateUserSpecified = true;
dsDefinition.WindowsCredentials = true;
dsDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store;
dsDefinition.UserName="ReportAccount";
dsDefinition.Password="ReportPassword";
//Upload it to reporting service
reportingService.CreateDataSourcde(sourceFileName, dataConnectionsLibraryUrl, true, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment