Upload video to SharePoint library by code - c#

I am making a app for SharePoint and have a form with several inputs for text and for files as well. The input for files works fine for regular files such as Word, Excel, PowerPoint, images etc... but wont work with videos. Is it possible to upload a video to a document library by code? Or cant you do that simply because the files is usually to big and would take long to upload?
The files is of the type HttpPostedFileBase and sent by a normal mvc form.
And this is the code for uploading it to the folder
FileCreationInformation attachFileInfo = new FileCreationInformation();
attachFileInfo.ContentStream = pNewRequest.FileToUpload1.InputStream;
attachFileInfo.Url = Path.GetFileName(pNewRequest.FileToUpload1.FileName);
newFolder.Files.Add(attachFileInfo);

According to this StackExchange answer, SP videos are organized in special VideoSet folders which seem to be similar to doc sets.
You said you're using MVC to submit the files so I'm assuming you're using CSOM on an external server. Here's an example for handling video uploads via CSOM.

Related

ASP.NET: Modify and download docx file

I have a docx file which I would like to modify according to web user input. So, after the user submits the form on the web page, I need to modify the original docx file, and then download it to the user.
I try to store the original file as a resource file in my project, but I can't open it programatically.
That's what I tried in the post controller:
using Microsoft.Office.Interop.Word;
...
Application app = new Application();
Document document = app.Documents.Open(Properties.Resources.___, ReadOnly: false);
But I received a System.Runtime.InteropServices.COMException (0x80020005 (DISP_E_TYPEMISMATCH))
I also don't know how to download the modified file. In a simple console application document.SaveAs2(newPath); worked, but it doesn't seem to work for downloading.
(I'm not even sure that this whole way could work. If I can't use Microsoft.Office.Interop.Word this way, please let me know.)
If you want to manipulate docx files it's best to use the OpenXML API rather than the InterOP. See https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk?redirectedfrom=MSDN

Check if the original content of files is not a script or exe content

I am working on file upload and download web App using .net mvc C# APIs and I have read this answer to consider some file security points and I have two questions:
According to the Filetypes point particularly this statement
It's best if the application uses some real content discovery to find
out if the uploaded file is actually an allowed filetype.
I want to check if the user uploads an .exe, .dll or "html containing js code"
file as renamed text file but i don't know how to do that.
According to Content sniffing point, I have added
X-Content-Type-Options: nosniff
To my api web.config file flowing this Answer
but when i upload html page including java script code it uploads and download without any interruption, so how to prevent my app from uploading and downloading these kinds of files.
There are plenty of ideas here (theoretical and practical):
https://security.stackexchange.com/questions/160129/c-malicious-file-upload-to-server
https://www.computerweekly.com/answer/File-upload-security-best-practices-Block-a-malicious-file-upload
I personally would suggest to white-list the extensions that will be allowed to upload, instead of black-listing potentially dangerous extensions.

Interact with aspx page to download a file from C#

I'm attempting to automate a task I have of interacting with a website form to download a file.
In human terms, I select a label from a list of options, and then press a submit button. The website then automatically downloads a zip file to the downloads folder.
The actions described above have the net effect of running this code in a browser console:
$('#ListBox1').val($('#ListBox1 option:first')) && $('#Download_0').click()
My question is, how can I download this zip file by running the code from a C# program? Ideally, I would also be able to specify where the file downloads to, although I'm not sure if this is possible.
Please note, this question is not asking how to download a file using C# (see: How to download a file from a website in C# and .net - Downloading a file from a website using C#). No such file exists on the website for me to download. The resulting file is generated and downloaded automatically by the two actions above.
EDIT:
The following code does download a file, however, the file is 24kb (the zip file I'm expecting is around 8mb) and unopenable:
using (WebClient client = new WebClient())
{
client.DownloadFile("https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx", AppDomain.CurrentDomain.BaseDirectory + "download.zip");
}
EDIT2:
What I'm attempting to do is download the most recent zip file available containing bulk call report data. The website selects the most recently available data automatically, but I have to manually select the type of file I want to download. As such, the web request won't be static and can't be hard-coded into the program, which is why I'm attempting to interact with the webpage.

Uploading files to site / datatable

I'm trying to make a little site for few people. Basically what i'm looking for is that users can register to this site, log on and upload files. I want the files to upload to a new folder that is named after the uID for example.
User Tommy registers and get user id 1234.
Then his upload folder will be
http://www.site.com/users/1234/upload/
He is the only one that has access to this data and can delete them.
Another way would be storing this info in the sql. I'm using MS SQL 2008. Can i save the upload attachments right in the datatable ? or should i have one account that has full rights that will make the folders for the users and save the direct link in the database ?
I'm going for a little, very so light version of dropbox.com but only in a browser form.
And if you go though folder route,
System.IO FileInfo and DirectoryInfo will give you all the info you need about the contents of a folder, and the files within it.
And dont forget Server.MapPath() :)
Take a look at FILESTREAM in SQL Server 2008, which is designed to efficiently store unstructured data.
BOL: FILESTREAM Overview

Displaying files in a directory

I am developing an ASP.NET 3.5 web application and I have a folder in the project which contains a list of documents which could be pdf or any of the MS office 2003 or 2007 supported file formats. I would like to display these files to my users as thumbnails (just like the way windows displays files). And when the user clicks on a file it has to prompt them to either save the file or open in the browser itself. How can I achieve this?
You can get the files like this (assuming /Documents)
string path = Server.MapPath(#"/Documents");
string[] files = System.IO.Directory.GetFiles(path);
And nou you only have to write some HTML generating code to display the files the way you want them displayed.
the answer at the following question seems to be RIGHT up your alley (ie the answer)
C# get thumbnail from file via windows api

Categories

Resources