How can I import external files into SDL Tridion 2011 using core service? - tridion

I want to push PDF, Word and Excel files into SDL Tridion 2011 by using core service.
I tried below code but get this error:
Invalid value for property 'BinaryContent'. Unable to open uploaded file:
using (ChannelFactory<ISessionAwareCoreService> factory =
new ChannelFactory<ISessionAwareCoreService>("wsHttp_2011"))
{
ISessionAwareCoreService client = factory.CreateChannel();
ComponentData multimediaComponent = (ComponentData)client.GetDefaultData(
ItemType.Component, "tcm:19-483-2");
multimediaComponent.Title = "MultimediaFile";
multimediaComponent.ComponentType = ComponentType.Multimedia;
multimediaComponent.Schema.IdRef = "tcm:19-2327-8";
using (StreamUploadClient streamClient = new StreamUploadClient())
{
FileStream objfilestream = new FileStream(#"\My Documents\My Poc\images.jpg",
FileMode.Open, FileAccess.Read);
string tempLocation = streamClient.UploadBinaryContent("images.jpg",
objfilestream);
}
BinaryContentData binaryContent = new BinaryContentData();
binaryContent.UploadFromFile = #"C:\Documents and Settings\My Poc\images.jpg";
binaryContent.Filename = "images.jpg";
binaryContent.MultimediaType = new LinkToMultimediaTypeData()
{
IdRef ="tcm:0-2-65544"
};
multimediaComponent.BinaryContent = binaryContent;
IdentifiableObjectData savedComponent = client.Save(multimediaComponent,
new ReadOptions());
client.CheckIn(savedComponent.Id, null);
Response.Write(savedComponent.Id);
}

Have a read of Ryan's excellent article here http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011
All binary files are handled the same way - so his technique for images will be equally as valid for documents, just make sure you use a Schema with the appropriate mime types.

The process for uploading binaries into Tridion using the Core Service is:
Upload the binary data to the Tridion server using a StreamUploadClient. This returns you the path of the file on the Tridion server.
Create a BinaryContentData that points to the file on the Tridion server (so with the path you got back from step 1)
Create a ComponentData that refers to the the BinaryContentData from step 2
Save the ComponentData
You are setting the local path for your file in step 2.
binaryContent.UploadFromFile = #"C:\Documents and Settings\My Poc\images.jpg";
But Tridion will never be able to find that file there. You instead should set the path that you got back from UploadBinaryContent:
string tempLocation;
using (StreamUploadClient streamClient = new StreamUploadClient())
{
FileStream objfilestream = new FileStream(#"\My Documents\My Poc\images.jpg",
FileMode.Open, FileAccess.Read);
tempLocation = streamClient.UploadBinaryContent("images.jpg", objfilestream);
}
BinaryContentData binaryContent = new BinaryContentData();
binaryContent.UploadFromFile = tempLocation;
Note that the Ryan's original code does exactly that.

Related

How to read a local json file and display

newbie here,I could not find any example on Xamarin Forms read a local json file and display it. I need to do a local testing to read the local Json file.
1) Where do I save the json file for reading? in Android and iOS Projects or just in PCL project?
2) How to read the file?
here the code but it is not complete as I dont how to read the file.
using (var reader = new System.IO.StreamReader(stream))
{
var json = reader.ReadToEnd();
var rootobject = JsonConvert.DeserializeObject<Rootobject>(json);
whateverArray = rootobject.Whatever;
}
The code miss the Path and others which required.
You can directly add your JSON file in PCL. Then change build action to Embedded Resource
Now you can read Json data by:
var assembly = typeof("<ContentPageName>").GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream("Your_File.json");
using (var reader = new System.IO.StreamReader(stream))
{
var json = reader.ReadToEnd();
var data= JsonConvert.DeserializeObject<Model>(json);
}

Getting File Path not supported while trying to download multimedia image from Tridion 2011 SP1

I am getting "The given path's format is not supported." when I am just trying to download multimedia image from my SDL Tridion 2011 SP1, below is the path I am getting, no idea how "N:" etc are coming.
D:\delete\Images\N:\dmc.FlipMedia.Clients.TestCMS\2009_WorkInProgress\creatives\05_May\Kids under 16 go free to UK\assets_graphics\jpg\Kids_go_free_385x306.jpg
Below is the code:
public static void GetBinaryFromMultimediaComponent(string tcm, CoreServiceClient client, StreamDownloadServiceClient streamDownloadClient)
{
ComponentData multimediaComponent = client.ReadItem(tcm) as ComponentData;
// Generate you own file name, and file location
string file = "D:\\delete\\Images\\" + multimediaComponent.BinaryContent.Filename;//Here I am getting above path
// Write out the existing file from Tridion
FileStream fs = File.Create(file);//Here getting the exception
byte[] binaryContent = null;
if (multimediaComponent.BinaryContent.FileSize != -1)
{
Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcm);
var memoryStream = new MemoryStream();
tempStream.CopyTo(memoryStream);
binaryContent = memoryStream.ToArray();
}
fs.Write(binaryContent, 0, binaryContent.Length);
fs.Close();
}
Please suggest!!
Edit:
I got filename using Nuno Suggestions, however moving forward to
Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcm);
I am getting below error, any suggestion on this?
The content type multipart/related; type="application/xop+xml";start="";boundary="uuid:5f66d04b-76d3-4d3a-b8e3-b7b91e00ed32+id=2";start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 595 bytes of the response were: ' --uuid:5f66d04b-76d3-4d3a-b8e3-b7b91e00ed32+id=2 Content-ID: Content-Transfer-Encoding: 8bit Content-Type: application/xop+xml;charset=utf-8;type="text/xml" '.
As you probably figured out by now, string file = "D:\\delete\\Images\\" + multimediaComponent.BinaryContent.Filename;will append full file name (including path) and therefore generate a wrong path.
Try using something like string file = "D:\\delete\\Images\\" + Path.GetFilename(multimediaComponent.BinaryContent.Filename);
Do this way:-
Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcmId);
MemoryStream memoryStream = new MemoryStream();
int b;
do
{
b = tempStream.ReadByte();
memoryStream.WriteByte((byte)b);
} while (b != -1);
binaryContent = memoryStream.ToArray();​

need to automate the RDLC reporting through SSIS script task?

Currently I'm calling RDLC report in asp.net application, where .rdlc is calling and we passing a data source and report in generated as PDF, the entire process initiate on a BUTTON click and report is generate.
Now this process need to automate and report should generate on Monday morning.
There is some suggestion come out that we can use SSIS Script Task and we can call external DLL and can call .rdlc file too to generate the report and then we can schedule SSIS package?
I never having experience on SSIS side, need your suggestion and how to do that, if there is possibilities? Thank You!
Use SSRS to schedule the report to run. No need for ASP.net or SSIS, SSRS has scheduling built in.
You can use SSRS subscription to send the report. If you really want the SSIS to send the report. you can do the following.
Create the report in SSRS
Deploy the report into report server
Create the SSIS package
Drag your Script task into the package.
You could use the following code snippet to send SSRS report using SSIS.
You should create some of the SSIS variables to store the report and render information.
RenderExtension ==> pdf
RenderFileName ==> Name of the file you want write
RenderFormat ==> PDF
RenderOutputPath==> Location to write the file
SSRSConnection ==>
http://localhost/ReportServer/reportexecution2005.asmx [Location of
your report services]
SSRSFolderName ==> Folder name of the report you deployed
SSRSReportName ==> Name of the report
In the following snippet.
public void Main()
{
var rExtension = Dts.Variables["RenderExtension"].Value.ToString();
var rFileName = Dts.Variables["RenderFileName"].Value.ToString();
var rFormat = Dts.Variables["RenderFormat"].Value.ToString();
var rOutputPath = Dts.Variables["RenderOutputPath"].Value.ToString();
var ssrsConnection = Dts.Variables["SSRSConnection"].Value.ToString();
var ssrsFolderName = Dts.Variables["SSRSFolderName"].Value.ToString();
var ssrsReportName = Dts.Variables["SSRSReportName"].Value.ToString();
ReportExecutionService rs=new ReportExecutionService();
Byte[] results;
string encoding = string.Empty;
string mimetype = string.Empty;
string extension = string.Empty;
Warning[] warnings = null;
string[] streamId = null;
string deviceInfo = null;
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = ssrsConnection;
try
{
var reportpath = string.Format("/{0}/{1}", ssrsFolderName, ssrsReportName);
rs.LoadReport(reportpath, null);
//Adding Parameters
//Commenting the following line Till we test the functionality
ParameterValue[] paramValues = new ParameterValue[4];
ParameterValue paramValue = new ParameterValue();
paramValue.Name = "ReportParamName";
paramValue.Value = "X,Y,Z";
paramValues[0] = paramValue;
rs.SetExecutionParameters(paramValues, "en-US");
results = rs.Render(rFormat, deviceInfo, out extension, out mimetype, out encoding, out warnings, out streamId);
var filewithdatetime = string.Format("{0}_{1}",rFileName,DateTime.Now.ToString("yyyy_MM_dd_hhmmss"));
string path = string.Format(#"{0}\{1}.{2}", rOutputPath, filewithdatetime, rExtension);
MessageBox.Show(path);
using (FileStream stream = File.OpenWrite(path))
{
stream.Write(results, 0, results.Length);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
}
Dts.TaskResult = (int)ScriptResults.Success;
}

How to access the properties and parts of an SSRS report at runtime

I'm using the ReportViewer control to display a server report in an ASP.NET page and I'm looking for a way to get the report into an object that I can then read and/or modify.
This kind of thing:
var rw = report.Width;
var t = ((Chart)report.Body.Item[3]).Title;
Is there a way, or am I stuck with parsing the XML file?
ETA:
I'm beginning to think I will need to access the XML file but I can't find out how to download that from the server, modify it (in memory) and then send it to the ReportViewer control.
ETA2:
Here's how to download the report definition (clean up left out for brevity):
// Download the report
var rs = new ReportingService2010();
rs.UseDefaultCredentials = true;
var reportDefinition = rs.GetItemDefinition("/DashboardReports/MyChart");
// Convert to XML
var ms = new MemoryStream(reportDefinition);
var doc = new System.Xml.XmlDocument();
doc.Load(ms);
// To load the stream into the report viewer
stream.Position = 0; // needed because we used the stream above - doc.Load(ms)
this.ReportViewer1.ServerReport.LoadReportDefinition(stream);

The given path's format is not supported

I am getting the following error while uploading the file from my local drive.
The given path's format is not supported.
The code is given.
Please tell me what changes I have to make.
string file0 = MapPathReverse(FileUpload1.PostedFile.FileName);// Get virtual path
string conversationFileSource = Server.MapPath(file0);
StreamReader file = new StreamReader(conversationFileSource);
If you want to access the input stream of the uploaded file:
using (StreamReader reader = new StreamReader(FileUpload1.PostedFile.InputStream))
{
...
}
If you want to save the uploaded file on some folder on your server:
var uploadsFolder = Server.MapPath("~/uploads");
var file = Path.Combine(uploadsFolder, Path.GetFileName(FileUpload1.PostedFile.FileName));
FileUpload1.PostedFile.SaveAs(file);

Resources