Download Latest File from SharePoint Server - c#

I have very little idea on sharepoint. Need a start,how to access the share point site and download the latest file avilable in a particular folder.
I am using ASP.Net/C#.Net and Visual Studio 2008 to download file.
What is requirement means any particular libraray/update/pathes?
How can i get to know path of webservice ? (I only know the direct URL)
Is it possible to access the metadata of the file.
Any help will be appreciated.
Thanks

I found this on a web search at some point. This is what I ended up using.
var remotefile = #"https://pathtoremotefile";
var localfile = #"C:\pathtolocalfile";
using(WebClient wc = new WebClient())
{
wc.Credentials = CredentialCache.DefaultNetworkCredentials;
// or new System.Net.NetworkCredential("user","pass","domain");
wc.DownloadFile(remotefile,localfile);
}

Related

Copy File to remote windows server using .net core

I have put endpoint that accept the zip file. The endpoint is working fine to get the zip file. Now from that endpoint after I get that file I am trying to copy that file to a different remote Server.
I try below code to connect to remote Server using the below code by referring to micrsoft docs https://learn.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity.runimpersonated?view=net-6.0:
bool returnValue = LogonUser(#"ACC\Test.test", "acc.local", "password",
9, 0,
out safeAccessTokenHandle);
if (returnValue)
{
WindowsIdentity.RunImpersonated(safeAccessTokenHandle, () =>
{
//Destination remote server folder to upload file
var pathToUploadFile = #"\\152.158.100.45\D\FileUpload";
string fileName;
fileName = file.FileName;
var path = Path.Combine(pathToUploadFile, fileName);
using (var stream = new FileStream(path, FileMode.Create))
{
//save a zip file to folder
file.CopyTo(stream);
}
});
}
In this code I get error of username and password is incorrect in this line of code:
var stream = new FileStream(path, FileMode.Create)
I am not even sure if the LogonUser method connects to a remote server. So is there is better way to do this copy file to remote server Please give an idea to implement in .net core 6.0 C#. Any help is really appreciated. Thanks
Finally I am able to solve the issue by implementing the Win32 API called WNetUseConnection solutions that was mentioned on below questions:
Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials

Get a file from a plugin in Microsoft Dynamics 365

I´ve installed Dynamics Version 1612 (8.2.2.112) (DB 8.2.2.112) on-premises. I wrote a plugin to connect to a web API, work perfect, now I need to add more situations. The API can return an url to a zipped file with the response in a JSON file. Well, there're any change to point me in the right direction? First, to get the file. STFW so far he gave me no clue. Thanks in advance.
If you have an URL then get unzip and process.
Example how to get and unzip file.
WebClient wc = new WebClient();
using (MemoryStream stream = new MemoryStream(wc.DownloadData("URL")))
{
using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
{
...
}
}

Downloading Files from website without knowing file name then extracting and moving to set location

I'm trying to download files using a list of urls. how would i go about downloading the files if your urls only end in the page where you would normally click the download button(it has a redirect and wait on the download also)?
i havent actually managed to get further than downloading a file using
but i know this wont work because i wont be able to know the filename and ill have to save it to a file in a config location
using (WebClient client = new WebClient())
{
client.DownloadFile("https://github.com/Hellzbellz123/downloadme/raw/master/TestAddon.7z", "testAddon.7z");
}
I intend to build a backend then plug it into a windows forms app for a gui because im really new to C# and programming in general
Do you mean that you don't know the filenames so you don't know how to save them locally?
If so:
//with 'url' as string
WebClient client = new WebClient();
Uri uri = new Uri(url);
client.DownloadFile(uri, uri.Segments.Last());
It takes the URL and splits it by every slash - the last item in the list is the filename..
EDIT: Improved, thanks to Jimi
That method won't work for links like "[..]/download.php?fileid="
For those links take a look at this

Download files using FluentFTP

I am trying to implement FTP transfer using FluentFTP in C#. Getting a directory listing is very easy, but I am stuck on downloading files.
I found one article that has an example in its comments here but it won't compile because I cannot find where the class FtpFile comes from.
Does anybody have an example of how tocan I download a file from an ftp server using FluentFTP ?
EDIT: I found some examples here https://github.com/hgupta9/FluentFTP But there is no example on how to actually download a file.
In the this article Free FTP Library there is an example but it does not compile. This is the example
FtpClient ftp = new FtpClient(txtUsername.Text, txtPassword.Text, txtFTPAddress.Text);
FtpListItem[] items = ftp.GetListing();
FtpFile file = new FtpFile(ftp, "8051812.xml"); // THIS does not compile, class FtpFile is unknown
file.Download("c:\\8051812.xml");
file.Name = "8051814.xml";
file.Download("c:\\8051814.xml");
ftp.Disconnect();
EDIT: The solution
The article I found contained an example that set me in the wrong direction.
It seems there was once a Download method but that is gone long ago now.
So the answer was to let that go and use the OpenRead() method to get a stream and than save that stream to a file.
There are now DownloadFile() and UploadFile() methods built into the latest version of FluentFTP.
Example usage from https://github.com/robinrodricks/FluentFTP#example-usage:
// connect to the FTP server
FtpClient client = new FtpClient();
client.Host = "123.123.123.123";
client.Credentials = new NetworkCredential("david", "pass123");
client.Connect();
// upload a file
client.UploadFile(#"C:\MyVideo.mp4", "/htdocs/big.txt");
// rename the uploaded file
client.Rename("/htdocs/big.txt", "/htdocs/big2.txt");
// download the file again
client.DownloadFile(#"C:\MyVideo_2.mp4", "/htdocs/big2.txt");

How to Generate Pre-signed url for Amazon S3 without using the SDK

I'd like to generate presigned URLs for images hosted on Amazon S3 without using the SDK. I'm currently using Rackspace to host my app and you can only do medium trust on their servers, so I can't use the SDK.
Any help is appreciated.
I'm doing this in C#.
Thanks.
What part is being restricted? I read through http://www.rackspace.com/knowledge_center/index.php/Overview_of_modified_Medium_Trust
You should be able to add the AWSSDK.dll to the bin of your application on the server. AWSSDK.dll found in the SDK install directory, on my machine it is C:\Program Files (x86)\AWS SDK for .NET\bin.
If that is still not allowing you access, you could run it on your local machine and intercept the actual call being made by the SDK, using fiddler. Then make the XML call directly from your own code.
This actually resolved the issue.
https://forums.aws.amazon.com/thread.jspa?threadID=39030&start=15&tstart=0
trick is to do this:
AmazonS3Config s3Config = new AmazonS3Config();
s3Config.UseSecureStringForAwsSecretKey = false;
AmazonS3Client s3Client = new AmazonS3Client(accessKey, secretKey, s3Config);

Categories