Hot answers tagged download
4
You can't push the file to the client from the server. The server side has no knowledge of the client side. You have to write a client application, that will pull the file.
First, you'll have to know the url of the file.
Then, a simple
var wc = new WebClient();
wc.UseDefaultCredentials = true;
wc.DownloadFile(targetFile, @"c:\temp\myfile.txt");
would ...
3
I believe this is what you are looking for. You can export a specific file or object from the Export-SPWeb context, not the whole kitten kaboodle.
Export-SPWeb -identity "http://sharepoint" -ItemUrl "/default.aspx" -Path "c:\default.aspx"
Import-SPWeb -identity "http://sharepoint" -Path "C:\default.aspx"
3
If your client code is running on server which means that request is being sent from server and your file will eventually downloaded on server. I would recommend you to write a code which runs on your computer and download the file from Server. You can Lists.asmx or OOTB Web Service to download the file from the Server.
2
As I understood you need source of the file from content DB to check it into Source Control. Please, try the following code:
Add-PSSnapin Microsoft.Sharepoint.Powershell
$web = Get-SPWeb <path to web>
$file = $web.GetFile('<relative path to file>');
$bytes = $file.OpenBinary();
[System.IO.File]::WriteAllBytes('<path to file on your disk>', ...
2
While Auditing is not available from the UI in Foundation, you can access the Audit functionality and turn it on via the object model:
http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/53e79142-88c9-48f1-b5a5-a6259c9f6f97
If you notice in this post, Auditing is advertised as a feature of Foundation, but it takes a little extra work to ...
2
you should use WebRequest
$web = Get-SPWeb $webUrl
$path = "C:\file.aspx"
$request = [System.Net.WebRequest]::Create($url)
$request.UseDefaultCredentials = $true
#do web request - if exception -> item does not exist
try {
$response = [System.Net.WebResponse]$request.GetResponse();
if ($response.StatusCode -ne "OK") {
write-host "Error: ...
1
If you are looking to track content within SharePoint itself, then SharePoint's own Audit logs should solve that request. They can track whenever any content in SharePoint is viewed, when and by whom. The reports are also available directly from the web UI though they are not as user-friendly as they could be.
For tracking all clicks. you might want to ...
1
somthing like this:
byte[] bytes = memoryStream.GetBuffer();
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=report.pdf");
Response.BinaryWrite(bytes);
Response.Flush();
...
1
AFAIK Save File Dialog, Open File Dialog are form controls and not web controls... So they will not work in Web environment!
You can use normal File Download code to let the user download the file and select where to save, see below links:
Download a file into client with ASP.NET 2.0
File Download in ASP.NET C#
Once you have the byte[] of the file, write ...
1
Another approach is possible :
$web = get-spweb http://server/yoursite
$file = $web.GetFile("$($web.Url)/pages/home.aspx")
[System.IO.File]::WriteAllBytes("$(gl)\$($file.Name)", $file.OpenBinary())
This will write in the current directory the content of the file "Pages/home.aspx"
1
The link can be reproduced using the following link, where "Documents" is the name of the library:
http://spsite/_layouts/download.aspx?SourceUrl=http://spsite/Documents/sample.docx
Effectively the download.aspx will read the content of the file you send as the SourceUrl, and render it back to you on the HTTP response.
Hope that helps
1
Check my step-by-step post: Working with document stored in SharePoint site using Document Connection
You will learn about how to:
Connect to a SharePoint site using Document Connection
Upload document into a document library
Check-Out/Check-In/Discard a document
Only top voted, non community-wiki answers of a minimum length are eligible

