Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find file's type
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Find file's type
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01648574
Message ID:
01648574
Vues:
35
Hi everybody,

I am wondering if someone has a routine to figure out file's type based on either its content or its filename. In my routine I have
 var streamProvider = new MultipartMemoryStreamProvider();
                    streamProvider = await Request.Content.ReadAsMultipartAsync(streamProvider);

                    foreach (
                        var item in
                        streamProvider.Contents.Where(c => !string.IsNullOrEmpty(c.Headers.ContentDisposition.FileName))
                    )
                    {
                        using (Stream stFileSource = new MemoryStream(await item.ReadAsByteArrayAsync()))                     {
                            byte[] fileBytes;
                            
                            fileBytes = new Byte[stFileSource.Length];
                            stFileSource.Read(fileBytes, 0, Convert.ToInt32(stFileSource.Length));
                            FileUploadResult file = new FileUploadResult()
                            {
                                FileName = item.Headers.ContentDisposition.FileName,
                                Content = fileBytes,
                                Key = Guid.NewGuid().ToString()
                            };
and in my FileUploadResult I added string property Type which I'd like to somehow discover from either content or extension (e.g. Image, PDF, Document, Excel - I think I limited my front-end to only those types).

The other question I have - is there a way to save information between different API calls? I'm trying right now a property of my API controller to hold list of files, but I'm not certain it will work - what is the normal way in MVC to persist information between API calls without a need to send information back to the page?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform