SSRS importer in C# 4.0, move reports from one server to another w/o changing format - c#-4.0

yes, i know about File.Copy(...), but is there a web service method that can do the same thing? i am also worried about credentials needed to access the server. the inputs are to be the report filepath and the url to the server i want to move the report to WITHOUT CHANGING THE FORMAT. i have been looking at the web service ReportService2005 but not so sure it will work. other web services i have available are: ReportExecution2005, ReportingServices, ReportService, and ReportService2006. i would like to stay away from using rs.exe as well.

// Determine filename without extension (used as name in SSRS)
FileInfo fileInfo = new FileInfo(FileSystemPath);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
try
{
// Determine filecontents
Byte[] fileContents = File.ReadAllBytes(fileInfo.FullName);
// Publish report
rsService.Warning[] warnings = this.rs.CreateReport(fileNameWithoutExtension, this.SSRSFolder, true, fileContents, null);
if (warnings != null)
{
foreach (rsService.Warning warning in warnings)
{
//Log warnings
}
}
}
catch
{
//handle error
}

Related

Unable to resolve sync conflict when using Azure Mobile Client - error keeps coming back

I'm using a Node.JS backend on Azure with Easy Tables. The table contains the required columns to support offline syncing.
While testing the sync process I noticed that conflicts keep coming back even though I'm resolving them.
My test:
Pull table content from Azure to iOS and Android device
Change a record on iOS but don't sync back to Azure
Change the same record on Android and sync
Now sync iOS
As expected, the conflict is detected correctly and I catch a MobileServicePushFailedException. I am then resolving the error by replacing the local item with the server item:
localItem.AzureVersion = serverItem.AzureVersion;
await result.UpdateOperationAsync(JObject.FromObject (localItem));
However, the next time I sync, the same item fails again with the same error.
The AzureVersion property is declared like this:
[Version]
public string AzureVersion { get; set; }
What exactly is result.UpdateOperationAsync() doing? Does it update my local database? Do I have to do it manually?
And also: am I supposed to trigger an explicit PushAsync() afterwards?
EDIT:
I changed the property from AzureVersion to Version and it works. I noticed that the serverItem's AzureVersion property was NULL even though the JSON contained it. Bug in Json.Net or in the Azure Mobile Client?
You should be using something like the following:
public async Task SyncAsync()
{
ReadOnlyCollection<MobileServiceTableOperationError> syncErrors = null;
try
{
await this.client.SyncContext.PushAsync();
await this.todoTable.PullAsync(
//The first parameter is a query name that is used internally by the client SDK to implement incremental sync.
//Use a different query name for each unique query in your program
"allTodoItems",
this.todoTable.CreateQuery());
}
catch (MobileServicePushFailedException exc)
{
if (exc.PushResult != null)
{
syncErrors = exc.PushResult.Errors;
}
}
// Simple error/conflict handling. A real application would handle the various errors like network conditions,
// server conflicts and others via the IMobileServiceSyncHandler.
if (syncErrors != null)
{
foreach (var error in syncErrors)
{
if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
{
//Update failed, reverting to server's copy.
await error.CancelAndUpdateItemAsync(error.Result);
}
else
{
// Discard local change.
await error.CancelAndDiscardItemAsync();
}
Debug.WriteLine(#"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]);
}
}
}
Note the CancelAndUpdateItemAsync(), which updates the item to the server copy or CancelAndDiscardItemAsync(), which accepts the local item. These are the important things for you.
This code came from the official HOWTO docs here: https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/##offlinesync

log4net web plugin location of log file

I have a windows forms application that runs in two different modes desktop mode and web plugin mode. I'm trying to put the log files using log4net in the same place. but when it is running as a web plugin my log file get put into the temporary internet folder of the users app data folder.
Code:
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
if (Uri.TryCreate(uri, "log4net.config", out uri))
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(uri.LocalPath));
}
_configured = true;
if (Utilities.WebPlugin)
{
var logNetHierarchy = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
foreach (var iAppender in logNetHierarchy.Root.Appenders)
{
if (iAppender is FileAppender)
{
var fileAppender = (FileAppender)iAppender;
fileAppender.File = #"C:\Users\" + Environment.UserName + #"\Company\Viewer\Web\log.xml";
fileAppender.ActivateOptions();
}
}
}
I would like to get them in the same place without including some kind of script.
stuartd was right soon as I put the site into trusted sites it worked perfectly.

File uploading from web application to Sharepoint server

This is my first time ever with Sharepoint. Here is the scenario
I have a stand alone web application
I also have a stand alone sharepoint server.
Both are on different servers.
I need to upload a file from web application to sharepoint
I found 2 methods online,
Using the webservice provided by Sharepoint (CopyIntoItems)
Using jQuery library of Sharepoint webservice
After searching the web, I think the jQuery part will not work (you can correct me).
I am looking for a method that takes username/password and uploads a pdf file to Sharepoint server. The following is my C# code that tries to upload but ends up in error
public bool UploadFile(string file, string destination)
{
bool success = false;
CopySoapClient client = new CopySoapClient();
if (client.ClientCredentials != null)
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
try
{
client.Open();
string filename = Path.GetFileName(file);
string destinationUrl = destination + filename;
string[] destinationUrls = { destinationUrl };
FieldInformation i1 = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = filename };
FieldInformation[] info = { i1 };
CopyResult[] result;
byte[] data = File.ReadAllBytes(file);
//uint ret = client.CopyIntoItems(filename, destinationUrls, info, data, out result);
uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
if (result != null && result.Length > 0 && result[0].ErrorCode == 0)
success = true;
}
finally
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
if (client.State != System.ServiceModel.CommunicationState.Closed)
client.Close();
}
return success;
}
I am calling the above function like this
UploadFile(#"C:\temp\uploadFile.txt", "http://spf-03:300/demo/Dokumente").ToString();
Error that i get:
Error Code: Destination Invalid
Error Message: The service method 'Copy' must be called on the same domain that contains the target URL.
There is the 3rd option with SharePoint 2010 and that is to use the Client Side object model. The client side object model a a sub set of the larger Sharepoint API, but it does cover uploading documents. Below is blog post with an example of uploading.
Upload document through client object model
As with most things in SharePoint you will need to authenticate against it the site, so find out if your site collection is forms based or claims based and then you should be able to find sample code for your situation.
Solution to the problem:
The problem was that the "security token webservice" was not working and it was giving some error when we manually ran the webservice.
The server was unable to process the request due to an internal error.
For more information about the error, either turn on
IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute
or from the configuration behavior) on the server in order to send the
exception information back to the client, or turn on tracing as per
the Microsoft .NET Framework 3.0 SDK documentation and inspect the
server trace logs.
The above exception is a generic one. To view the exact exception we enabled remote error viewing from the web.config file of the webservice(link) and saw the exact exception.
We found the solution for the exception and the service started. After that everything was working fine.

Connect to FTP server and download file from FTP to local machine

I need to know a way to connect to a FTP site and i am unable to find an example to do the program using C#.
I need to write the code where i could connect, and download files from the FTP server without using third party component.
How can i do this ? Help.
There is FtpWebRequest class in .Net 4
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
There are examples at the end. Here is a sample taken from msdn:
public static bool DisplayFileFromServer(Uri serverUri)
{
// The serverUri parameter should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
// Get the object used to communicate with the server.
WebClient request = new WebClient();
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe#contoso.com");
try
{
byte [] newFileData = request.DownloadData (serverUri.ToString());
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
Console.WriteLine(fileString);
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
return true;
}
This isn't specifically a question as such.
You need to use the socket classes within the .NET framework:
MSDN - System.Net.Sockets
A good example I've previously used is:
www.dreamincode.net - Create an ftp class library

FtpWebRequest + Windows Azure = not working?

Is it possible download data on Windows Azure via FtpWebRequest (ASP.NET/C#)?
I am doing this currently and not sure if my problem is that FtpWebRequest is in general not working as expected, or if I have a different failure..
Has sb. did this before?
If you're talking about Windows Azure Storage, then definitely not. FTP is not supported.
If you're working with Compute roles, you could write something to support this, but it's DIY, a la:
http://blog.maartenballiauw.be/post/2010/03/15/Using-FTP-to-access-Windows-Azure-Blob-Storage.aspx
I could solve my problem doing the ftp-request with FTPLib.
This means: You can copy/load files to azure or to an external source!
:-)
Make this working also with AlexFTPS , you just need to add StartKeepAlive.
try
{
string fileName = Path.GetFileName(this.UrlString);
Uri uri = new Uri(this.UrlString);
string descFilePath = Path.Combine(this.DestDir, fileName);
using (FTPSClient client = new FTPSClient())
{
// Connect to the server, with mandatory SSL/TLS
// encryption during authentication and
// optional encryption on the data channel
// (directory lists, file transfers)
client.Connect(uri.Host,
new NetworkCredential("anonymous",
"name#email.com"),
ESSLSupportMode.ClearText
);
client.StartKeepAlive();
// Download a file
client.GetFile(uri.PathAndQuery, descFilePath);
client.StopKeepAlive();
client.Close();
}
}
catch (Exception ex)
{
throw new Exception("Failed to download", ex);
}

Resources