Now on my PC I can use explorer to open a location on our SP server (location eg http://sp.myhost.com/site/Documents/). And from there I can copy/paste a file from eg my C:\ drive.
I need to replicate the copy process progmatically. FileCopy() doesn't do it - seems to be the http:// bit that's causing problems!
Does the server allow WebDAV access? If yes, there are WebDAV clients for Delphi available, including Indy 10.
In case if you are not using BLOB storage all SharePoint files are stored in the database as BLOB objects.
When you access your files with explorer you are using windows service which is reading files from SharePoiont and render it to you. This way you can copy and paste as soon as donwload them from an to SharePoint manually.
To be able to do this automatically you should achive this using the next SP API code:
using (SPSite site = new SPSite("http://testsite.dev"))
{
using (SPWeb web = site.OpenWeb())
{
using (FileStream fs = File.OpenRead(#"C:\Debug.txt"))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int) fs.Length);
SPList list = web.GetList("Lists/Test AAD");
SPFile f = list.RootFolder.Files.Add("/Shared Documents/"+Path.GetFileName(fs.Name), buffer);
}
}
}
This will add new "Debug.txt" file to the "Shared Documents" library read from the disk C. To do this for each file just loop through each file in the folder. You can open web only once and do the loop each time when you add file...
Hope it helps,
Andrew
Related
I am trying to get only existing file names list with respected date and time from SharePoint using any API and C#.
I am able to download and upload files from SharePoint using webclient, but i am not able to get only file names list with respected date and time to datagridview. Please let me know if there is any solution for that.
I am developing in windows forms application using visual studio environment.
Thanks,
Please try the c# code below to get the information about the files in directory
class FileSysInfo
{
static void Main()
{
// Get the files in the directory and prints out filename, Last access time and length
System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.*");
foreach (System.IO.FileInfo fi in fileNames)
{
Console.WriteLine("{0}: {1}: {2}", fi.Name, fi.LastAccessTime, fi.Length);
}
}
}
I need to be able to launch Excel and open and eiut a specific file from an MVC application.
The application is for internal use only and users will have access to the folder containing the excel file.
I have looked at the File method below
var dir = location + "Filename.xlsx";
var cd = new ContentDisposition
{
FileName = "Excel Spreadsheet",
Inline = true
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(dir, "application/vnd.ms-excel");
However, this opens Excel with a copy of the file downloaded to the users's download directory. So if they make any changes, these do not update to the original.
Is what I'm trying to do possible? If so, how?
Many thanks,
Chris.
I have a MVC application that uses NPOI version:2.1.3.0 to read and write in excel file and user can download that excel file in their local machine. File format: xlsx.
public ActionResult NPOI()
{
FileStream fs = new FileStream(Server.MapPath(#"\Content\SampleExcel.xlsx"), FileMode.Open, FileAccess.Read);
XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
ISheet sheet = (ISheet)templateWorkbook.GetSheet("Sheet1");
IRow dataRow = (IRow)sheet.GetRow(1);
dataRow.GetCell(0).SetCellValue(77);
sheet.ForceFormulaRecalculation = true;
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "SampleExcel.xlsx");
}
Writing in excel file is working fine. But when browser is IE and excel 2013 in user machine.
If after downloads completes user uses IE open(preview file) option is selected:
Then in excel 2013 this error is observed:
Followed by:
Although the template file(SampleExcel.xlsx) which is there on server side is open and saved with excel 2013. Then also I don't know why it is showing file is corrupt. And there is enough memory on user's machine, it never touches it's peak value in task manager.
Any help would be highly appreciated.
I figured it out, actually the problem is not with the memory, but with the user permission on that particular machine. If Admin guys try to do same above mentioned steps with no customization in access then no problem is faced by him.
Anyhow thanks everyone for your time:)
I have an aspnet app which i upload files to the azure blobs. I know that azure don't create structural paths in the containers, just blobs, but you can emulate directories putting a "/" on the uri.
i.e
I'd upload a list of files and my uri is like this
http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/FileName01.jpg
http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/FileName02.jpg
http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/FileName03.jpg
My download method:
public RemoteFile Download(DownloadRequest request)
{
var fileFinal = string.Format("{0}/{1}/{2}",request.IDProtocol ,request.IDDocument, request.FileName);
var blobBlock = InitializeDownload(fileFinal);
if (!blobBlock.Exists())
{
throw new FileNotFoundException("Error");
}
var stream = new MemoryStream();
blobBlock.DownloadToStream(stream);
return File(request.FileName)
}
private CloudBlob InitializeDownload(string uri)
{
var blobBlock = _blobClient.GetBlobReference(uri);
return blobBlock;
}
This way, i'm getting just one file. But i need to see and download all files inside http://myaccount.windowsazure.blob.net/MyProtocolID-01/MyDocumentID-01/
Thanks
Adding more details. You will need to use one of the listing APIs provided by the client library: CloudBlobContainer.ListBlobs(), CloudBlobContainer.ListBlobsSegmented(), and CloudBlobContainer.ListBlobsSegmentedAsync() (and various overloads.). You can specify the directory prefix, and the service will only enumerate blobs matching the prefix. You can then download each blob. You may also want to look at the ‘useFlatBlobListing’ argument, depending on your scenario.
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx
In addition AzCopy (see http://blogs.msdn.com/b/windowsazurestorage/archive/2012/12/03/azcopy-uploading-downloading-files-for-windows-azure-blobs.aspx) also supports this scenario of downloading all blobs in a given directory path.
Since each blob is a separate web resource, function above will download only one file. One thing you could do is list all blobs using the logic you are using and then download those blobs on your server first, zip them and the return that zip file to your end user.
Use AzCopy functionalities, now, it has a lot of supports.
https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
We are trying to upload a document from our local machine to server. We know that .NET browse control can be used for this but our requirement is to just have a button and call that as "Save Document". On click we know the path and also the document name, all we need to do is search the document in local machine (inside temp folder) and if the document is available then pick it and save it to our APP data folder on the server.
it's easy to achieve this using .NET borwse control but not sure how to do that same using normal button?
To find a file in a folder:
FileInfo file = Directory.GetFiles(#"c:\folder")
.FirstOrDefault(f => f.name = whatever);
To copy file:
File.Copy(file.FullName, targetPath, true);