myroslava72
myroslava72

Reputation: 435

Unzip file uploaded to Azure Web Apps using C#

My question is very similar to this one Unzip file uploaded to Azure Websites - I need to unzip a zip file which is on remote server. The difference is that I need to accomplish this using C# code. Is it possible?

Upvotes: 0

Views: 1508

Answers (1)

myroslava72
myroslava72

Reputation: 435

It is possible with this API https://github.com/projectkudu/kudu/wiki/REST-API#zip. The API actually does for you both zip file uploading and extracting.

Thanks to Suwat Ch and his answer here https://social.msdn.microsoft.com/Forums/azure/en-US/7fb2deed-6d1e-4529-9249-f67c83f373af/unzip-file-uploaded-to-azure-web-apps-using-c?forum=windowsazurewebsitespreview#7fb2deed-6d1e-4529-9249-f67c83f373af I managed to get it to work:

public void UploadZipToAzure()
        {
            byte[] projectFile = File.ReadAllBytes(@"C:\YourZipFile.zip");

            String Url = "https://YourAzureWebAppName.scm.azurewebsites.net/api/zip/site/wwwroot/";
            WebRequest request = WebRequest.Create(Url);

            request.ContentType = "application/x-zip-compressed";
            request.Method = "PUT";
            //Your Azure FTP deployment credentials here
            request.Credentials = new NetworkCredential("UserName - Azure's FTP deployment server name", "Password - Azure's FTP deployment server password");

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(projectFile, 0, projectFile.Length);
            requestStream.Close();

            WebResponse response = request.GetResponse();
        }

Upvotes: 3

Related Questions