Click here to Skip to main content
14,880,190 members
Home / Discussions / ASP.NET
   

ASP.NET

 
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 
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 
Thanks buddy ,
I Solved it..................
I didn't know there is a joke like you exists.....
I don't even change my code for a single word......
Actually you don't even know .... what i was talking about....??? Laugh | :laugh:
But the best part is you starting to comment on it..... Isn't it a joke.......??????
Is was a windows service which can move file to desire destination and insert data into sql server in my desired table......
So don't comment in a conversion if you are not able to understand it....
Here is the code for you...
Please run it with VS 2015 and then install the service and check it.........
<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.IO;
using System.Timers;
using System.Configuration;
using System.Data.OleDb;


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

        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("*.xlsx");



            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 12.0;Persist Security Info=False";
                WriteLog("declare excel oledb connection");
                OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);

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

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

                dReader = cmd.ExecuteReader();

                SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);

                sqlBulk.DestinationTableName = "shrabon";
                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 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();
        }


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


And the AppConfig is

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <appSettings>
    <add key="IntervalInSeconds" value="5"/>
    <add key="sourcepath" value="F:\shrabon"/>
    <add key="destinationPath" value="E:\Test"/>
    <add key="ExcelPath" value="E:\Test\"/>
    <add key="LogPath" value="E:\Floralog"/>
    <add key="MovePath" value="E:\Test\bak\"/>
    <add key="SourceFilePath" value="E:\Test"/>
    <add key="constr" value="Data Source=.;Initial Catalog=zam;User ID=eftuser;Password=eftuser321"/>
  </appSettings>
</configuration>


Thanks for Showing off... But Now i know What you are
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 
PraiseRe: Need a article on repository and data access code unit testing Pin
Mou_kol19-Sep-17 23:56
MemberMou_kol19-Sep-17 23:56 
Questionvb.net 2010 web form app point to correct .net framework Pin
dcof15-Sep-17 14:49
Memberdcof15-Sep-17 14:49 
QuestionAdding API's to website Pin
Member 1271965814-Sep-17 10:35
MemberMember 1271965814-Sep-17 10:35 
QuestionHow do I handle nulls in RadioButtonList in Repeater? Pin
samflex13-Sep-17 9:50
Membersamflex13-Sep-17 9:50 

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.