Click here to Skip to main content
14,876,850 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? Pin
samflex25-Sep-17 8:23
Membersamflex25-Sep-17 8:23 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? Pin
Richard Deeming25-Sep-17 10:43
mveRichard Deeming25-Sep-17 10:43 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? Pin
samflex25-Sep-17 10:58
Membersamflex25-Sep-17 10:58 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? Pin
samflex26-Sep-17 6:56
Membersamflex26-Sep-17 6:56 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? Pin
Richard Deeming26-Sep-17 7:21
mveRichard Deeming26-Sep-17 7:21 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? (SOLVED) Pin
samflex26-Sep-17 7:59
Membersamflex26-Sep-17 7:59 
GeneralRe: Repeater2 is not getting populated with data from Repeater2. Any ideas? Pin
Richard Deeming26-Sep-17 8:05
mveRichard Deeming26-Sep-17 8:05 
QuestionMy service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345320-Sep-17 1:26
professionalMember 1286345320-Sep-17 1:26 
<pre>using System;
using System.ServiceProcess;
using System.Data.SqlClient;
using System.IO;
using System.Timers;
using System.Configuration;
using System.Data.OleDb;
using System.Data;




namespace MoveToDesiredDest
{
    public partial class Service1 : ServiceBase
    {
        long delay = 5000;
        protected string LogPath = ConfigurationManager.AppSettings["LogPath"];
        protected string MoveFilePathPath = ConfigurationManager.AppSettings["MovePath"];

        public Service1()
        {
            InitializeComponent();


            Timer timer1 = new Timer();
            timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            timer1.Interval = delay;
            timer1.Enabled = true;
            timer1.Start();
        }

        protected override void OnStart(string[] args)
        {
            WriteLog("Service started");


            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }

            try
            {

                delay = Int32.Parse(ConfigurationManager.AppSettings["IntervalInSeconds"]) * 1000;
            }
            catch
            {
                WriteLog("IntervalInSeconds key/value incorrect.");
            }


            if (delay < 5000)
            {
                WriteLog("Sleep time too short: Changed to default(5 secs).");
                delay = 5000;
            }

            //Timer timer1 = new Timer();
            //timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            //timer1.Interval = delay;
            //timer1.Enabled = true;


        }

        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            write();
            Upload();
        }
      
        private void write() 
        {

            string sourcepath = ConfigurationManager.AppSettings["sourcepath"];
            WriteLog("Set source path");
            string[] sourcefiles = Directory.GetFiles(sourcepath);
            WriteLog("Get soutce path file");

            foreach (string childfile in sourcefiles)
            {
                WriteLog("Start to find file from loop");
                string sourceFileName = new FileInfo(childfile).Name;
                string destinationPath = ConfigurationManager.AppSettings["destinationPath"];

                string destinationFileName = sourceFileName;
                string sourceFile = Path.Combine(sourcepath, sourceFileName);
                WriteLog("Get file from source to destination");
                string destinationFile = Path.Combine(destinationPath, destinationFileName);
                WriteLog("Ready to copy");
                File.Copy(sourceFile, destinationFile, true);
                WriteLog("File copied");
                File.Delete(sourceFile);
                WriteLog("File deleted");
            }
        }
        protected void Upload()
        {
            string excelPath = ConfigurationManager.AppSettings["ExcelPath"];
            DirectoryInfo d = new DirectoryInfo(excelPath);
            FileInfo[] Files = d.GetFiles("*.xls");



            string str = "";
            WriteLog("ready to enter into loop");
            foreach (FileInfo file in Files)
            {
                str = file.Name;
                string sourceFilePath = ConfigurationManager.AppSettings["SourceFilePath"];
                string SourceFileName = Path.Combine(sourceFilePath, str);

                string destinationFilePath = ConfigurationManager.AppSettings["MovePath"];

                string destinationFileName = destinationFilePath + str;




                WriteLog("get file :" + str);
                String strConnection = ConfigurationManager.AppSettings["constr"];
                WriteLog("declare database connection");
                string path = excelPath + str;

                // string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 8.0;HDR =YES;Persist Security Info=False";
                string excelConnectionString = @"Microsoft.Jet.OLEDB.4.0;Data Source=" + path +";Extended Properties=Excel 8.0;HDR =YES;Persist Security Info=False";
                WriteLog("declare excel oledb connection");
                OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);

                OleDbCommand cmd = new OleDbCommand("Select [ID],[Name] from [Sheet1$]", excelConnection);

                    //("Select [Department No],[Department],[Emp No],[Name],[Date],[First],[Last] from [Sheet1$]", excelConnection);

                excelConnection.Open();
                WriteLog("oledb open");
                OleDbDataReader dReader;

                dReader = cmd.ExecuteReader();

                SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);

                sqlBulk.DestinationTableName = "Test1";
                WriteLog("ready to insert into database");
                sqlBulk.WriteToServer(dReader);
                WriteLog("data inserted");
                excelConnection.Close();
                WriteLog("Process completed");
                File.Move(SourceFileName, destinationFileName);
                WriteLog("File moved to bak folder");
                excelConnection.Close();
                cmd.Dispose();
            }
        }

       
        protected override void OnStop()
        {
            WriteLog("service stopped");
        }


        protected void WriteLog(string Msg)
        {
            FileStream fs = new FileStream(LogPath + "\\" + System.DateTime.Today.ToString("yyyyMMdd") + ".log", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine(System.DateTime.Now.ToString() + ": " + Msg);
            sw.Close();
            sw.Dispose();
            fs.Close();
            fs.Dispose();
        }
    }
}

AnswerRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Nathan Minier20-Sep-17 1:43
professionalNathan Minier20-Sep-17 1:43 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345320-Sep-17 18:58
professionalMember 1286345320-Sep-17 18:58 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Nathan Minier21-Sep-17 1:43
professionalNathan Minier21-Sep-17 1:43 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345322-Sep-17 23:44
professionalMember 1286345322-Sep-17 23:44 
AnswerRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Richard MacCutchan20-Sep-17 21:38
mveRichard MacCutchan20-Sep-17 21:38 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345320-Sep-17 21:52
professionalMember 1286345320-Sep-17 21:52 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Richard MacCutchan20-Sep-17 22:16
mveRichard MacCutchan20-Sep-17 22:16 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345320-Sep-17 22:33
professionalMember 1286345320-Sep-17 22:33 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Richard MacCutchan20-Sep-17 22:53
mveRichard MacCutchan20-Sep-17 22:53 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345320-Sep-17 22:56
professionalMember 1286345320-Sep-17 22:56 
GeneralRe: My service move my file Location but doesn't upload the data in sql server... here is my code Pin
Member 1286345322-Sep-17 23:46
professionalMember 1286345322-Sep-17 23:46 
QuestionUnable to cast object of type 'System.DBNull' to type 'System.String'. Pin
samflex19-Sep-17 5:35
Membersamflex19-Sep-17 5:35 
AnswerRe: Unable to cast object of type 'System.DBNull' to type 'System.String'. Pin
Richard Deeming19-Sep-17 6:04
mveRichard Deeming19-Sep-17 6:04 
GeneralRe: Unable to cast object of type 'System.DBNull' to type 'System.String'. Pin
samflex19-Sep-17 9:17
Membersamflex19-Sep-17 9:17 
QuestionDot Net Core 1.1 Static files(css,fonts,js) are not getting loaded when I am deploying my site in a Sub Domain Pin
IncodeSolutions18-Sep-17 19:58
MemberIncodeSolutions18-Sep-17 19:58 
QuestionNeed a article on repository and data access code unit testing Pin
Mou_kol17-Sep-17 22:54
MemberMou_kol17-Sep-17 22:54 
AnswerRe: Need a article on repository and data access code unit testing Pin
F-ES Sitecore18-Sep-17 0:07
mveF-ES Sitecore18-Sep-17 0:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.