Ola Akin

Ola Akin

  • NA
  • 1
  • 1.1k

Saving Multiple Files

Jun 30 2013 6:42 PM

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Sql;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.ServiceModel;
using v10GetWorkersExample.v10HumanResourcesReference;


namespace v10GetWorkersExample
{
    class Program
    {
        static void Main(string[] args)
        {

            // Force the user to press ENTER to start
            Console.WriteLine("Press <Enter> to run...");
            Console.ReadLine();

            // Create then "client"
            Human_ResourcesPortClient client = new Human_ResourcesPortClient("Human_Resources");

           

            client.ClientCredentials.UserName.UserName = "myusername";
            client.ClientCredentials.UserName.Password = "mypassword";

            // Set the Endpoint URI
            client.Endpoint.Address = new EndpointAddress("http://myendpoint");

            // Define the paging defaults
            decimal totalPages = 1;
            decimal currentPage = 1;
            decimal countSize = 200;

            // Set the current date/time
            //DateTime currentDateTime = DateTime.UtcNow;
            DateTime currentDateTime = DateTime.Now;

            // Loop over all of the pages in the web service response
            while (totalPages >= currentPage)
            {
                // Create a "request" object
                Get_Workers_RequestType request = new Get_Workers_RequestType();

                // Set the WWS version desired               
                request.version = "v10";

                // Set the date/time & page parameters in the request
                request.Response_Filter = new Response_FilterType();
                request.Response_Filter.As_Of_Entry_DateTime = currentDateTime;
                request.Response_Filter.As_Of_Entry_DateTimeSpecified = true;
                request.Response_Filter.As_Of_Effective_Date = new DateTime(2009, 4, 10);
                request.Response_Filter.As_Of_Effective_DateSpecified = true;
                request.Response_Filter.Page = currentPage;
                request.Response_Filter.PageSpecified = true;
                request.Response_Filter.Count = countSize;
                request.Response_Filter.CountSpecified = true;

                // Set the desired response group(s) to return
                request.Response_Group = new Worker_Response_GroupType();
                request.Response_Group.Include_Reference = true;
                request.Response_Group.Include_ReferenceSpecified = true;
                //request.Response_Group.Include_Personal_Information = true;
                //request.Response_Group.Include_Personal_InformationSpecified = true;
                //request.Response_Group.Include_Employment_Information = true;
                //request.Response_Group.Include_Employment_InformationSpecified = true;
                //request.Response_Group.Include_Compensation = true;
                //request.Response_Group.Include_CompensationSpecified = true;
                //request.Response_Group.Include_Organizations = true;
                //request.Response_Group.Include_OrganizationsSpecified = true;
                //request.Response_Group.Include_Management_Chain_Data = true;
                //request.Response_Group.Include_Management_Chain_DataSpecified = true;
                //request.Response_Group.Include_Benefit_Enrollments = true;
                //request.Response_Group.Include_Benefit_EnrollmentsSpecified = true;
                //request.Response_Group.Include_Benefit_Eligibility = true;
                //request.Response_Group.Include_Benefit_EligibilitySpecified = true;
                //request.Response_Group.Include_Related_Persons = true;
                //request.Response_Group.Include_Related_PersonsSpecified = true;
                //request.Response_Group.Include_Qualifications = true;
                //request.Response_Group.Include_QualificationsSpecified = true;
                //request.Response_Group.Include_Employee_Review = true;
                //request.Response_Group.Include_Employee_ReviewSpecified = true;
                //request.Response_Group.Include_Photo = true;
                //request.Response_Group.Include_PhotoSpecified = true;
                //request.Response_Group.Include_Worker_Documents = true;
                //request.Response_Group.Include_Worker_DocumentsSpecified = true;
                //request.Response_Group.Include_Transaction_Log_Data = true;
                //request.Response_Group.Include_Transaction_Log_DataSpecified = true;
                //request.Response_Group.Include_Succession_Profile = true;
                //request.Response_Group.Include_Succession_ProfileSpecified = true;
                //request.Response_Group.Include_Talent_Assessment = true;
                //request.Response_Group.Include_Talent_AssessmentSpecified = true;


                //request.Response_Group.Include_Roles = true;
                //request.Response_Group.Include_RolesSpecified = true;
                //request.Response_Group.Include_Personal_Information = true;
                //request.Response_Group.Include_Personal_InformationSpecified = true;

                // Create a "response" object
                Get_Workers_ResponseType response = client.Get_Workers(request);

                // Display all Workers
                for (int i = 0; i < response.Response_Data.Length; i++)
                {
                    if (response.Response_Data[i] != null)
                    {
                        
                        System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(response.GetType());
                        System.IO.TextWriter tw = new System.IO.StreamWriter("D:\\chamila\\XMLTest\\text.xsd");
                        x.Serialize(tw, response);
                        tw.Flush();
                        tw.Close();


                    }
                }

                // Update page number
                if (totalPages == 1) totalPages = response.Response_Results.Total_Pages;
                currentPage++;

            }

            Console.WriteLine();
            Console.WriteLine("Press <Enter> to end!");
            Console.ReadLine();

           client.Close();

         }

---

This code is requesting multiples files but only saving one of them. Could someone tell me how I can store multiple files using this code?

This is the part of the code that is storing

System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(response.GetType());
System.IO.TextWriter tw = new System.IO.StreamWriter("D:\\chamila\\XMLTest\\text.xsd");
x.Serialize(tw, response);
tw.Flush();
tw.Close();


Answers (1)