วันพุธที่ 24 กุมภาพันธ์ พ.ศ. 2559

How to comfigure asp session state settings for a site or application

ไม่มีความคิดเห็น:
เจอปัญหาผู้ใช้งาน Login เข้าใช้งานระบบเสร็จแล้วปล่อยทิ้งไว้ 15 นาที พอจะกลับมาใช้งานอีกที Session หมดอายุ ระบบให้กลับไป Login ใหม่
วิธีแก้ตามลิงค์นี้
 https://www.iis.net/configreference/system.webserver/asp/session
Read More

วันอังคารที่ 2 มิถุนายน พ.ศ. 2558

SQL DATEDIFF converting date and/or time from character string

ไม่มีความคิดเห็น:

I Use Function for [Worked]


ALTER FUNCTION [dbo].[FNDATEDIFF] 
(
	-- Add the parameters for the function here
	@StartDate VARCHAR(8),
	@EndDate VARCHAR(8)
)
RETURNS VARCHAR(8)
AS
BEGIN
	
	IF (isdate(@StartDate) = 0)
		RETURN 0
	IF (isdate(@EndDate) = 0)
		RETURN 0
		
	RETURN  DATEDIFF(day,@StartDate,@EndDate)

END

How to Use


select dbo.FNDATEDIFF('20110725','20110923') as 'DiffDate' 
select dbo.FNDATEDIFF('20110725','') as 'DiffDate'
select dbo.FNDATEDIFF('','') as 'DiffDate'
select dbo.FNDATEDIFF('','20110923') as 'DiffDate'

Result
DiffDate
60
DiffDate
0
DiffDate
0
DiffDate
0

Read More

วันจันทร์ที่ 18 พฤษภาคม พ.ศ. 2558

Uploading a Folder in Asp.net MVC4

2 ความคิดเห็น:
View
@{
    ViewBag.Title = "uploadFolder";
}

upload Folder

Script


Controllor
        public ActionResult uploadFolder()
        {
            return View();
        }

        [HttpPost]
        public async Task UploadHomeReport()
        {
            try
            {
                foreach (string file in Request.Files)
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        // get a stream
                        var stream = fileContent.InputStream;
                        // and optionally write the file to disk
                        var fileName = fileContent.FileName;
                        fileName = fileName.Replace(@"/",@"\");
                        string[] arr = fileName.Split('\\');
                        //\tculms\sub\sub1
                        var tempPath = string.Empty;
                        for (int i = 0; i < arr.Length; i++) {
                            if (!isFolder(arr[i]))
                            {
                                var targetPath = string.Empty;
                                if (i == 0)
                                {
                                    targetPath = Path.Combine(Server.MapPath("~/Images"), arr[i]);
                                    tempPath = tempPath + "\\" + arr[i];
                                    if (!System.IO.Directory.Exists(targetPath))
                                    {
                                        System.IO.Directory.CreateDirectory(targetPath);
                                    }
                                }
                                else
                                {
                                    tempPath = tempPath + "\\" + arr[i];
                                    targetPath = Server.MapPath("~/Images") + tempPath;
                                    //targetPath = Path.Combine(Server.MapPath("~/Images"), tempPath);
                                   
                                    if (!System.IO.Directory.Exists(targetPath))
                                    {
                                        System.IO.Directory.CreateDirectory(targetPath);
                                    }
                                }
                                
                            }
                        }
                        var path = Path.Combine(Server.MapPath("~/Images"), fileName);
                        using (var fileStream = System.IO.File.Create(path))
                        {
                            stream.CopyTo(fileStream);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return Json("Upload failed");
            }

            return Json("File uploaded successfully");
        }

        private bool isFolder(string txt) {
            var arr = txt.ToCharArray();
            for (int i = 0; i < arr.Length;i++ )
            {
                if (arr[i] == '.') {
                    return true;
                }
            }
            return false;
        }
Web config
  
    
    
    
  
  
   
      
         
      
    
    
      

  
Result


Derivative



Read More

Maximum request length exceeded

ไม่มีความคิดเห็น:
Read More

วันพุธที่ 8 เมษายน พ.ศ. 2558

IIS Accessing Network Share

ไม่มีความคิดเห็น:
ใช้งานได้
ดูรายละเอียด : http://stackoverflow.com/questions/14611015/iis7-accessing-network-share
Read More

[c#] Accessing a network file share

ไม่มีความคิดเห็น:

static void Main(string[] args)
        {
            //var system = System.IO.Directory.GetFiles(@"\\LENOVO-PC\joke\teacher\");
            DirectoryInfo dir = new DirectoryInfo(@"\\LENOVO-PC\joke\teacher\");//
            FileInfo fi = new FileInfo(@"\\LENOVO-PC\joke\teacher\image\1857784.jpg");
            bool exists = fi.Exists;
            while (true) { }
        }

ตัวอย่างจาก
http://stackoverflow.com/questions/20138569/reading-files-from-server-is-being-mapped-always-c-drive

http://stackoverflow.com/questions/18240909/accessing-a-network-file-share-with-c-sharp
Read More

วันอังคารที่ 31 มีนาคม พ.ศ. 2558

C# Calculate Standard Deviation (Using List Object)

ไม่มีความคิดเห็น:
สร้าง Class StandardDeviation ไว้คำนวนค่าหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
public class StandardDeviation {
        private double ExP2 { set; get; } //Ex^2
        private double Ex2 { set; get; }//(Ex)^2
        private List listScore { set; get; }
        private int n { set; get; }

        private double sum {set;get;}

        public StandardDeviation(List scores){
            this.listScore = scores;
            this.n = scores.Count;
        }

        public double Calculator(){
             calExP2();
             CalEx2();
             /*แทนค่าในสูตร 
                สูตร s.d = รูท nEx^2 - (Ez)^2 / n(n-1)
            */
            double g1 = this.n*this.ExP2 - this.Ex2;
            int g2 = this.n * (this.n - 1);

            sum = Math.Sqrt(g1 / g2);
             return sum;
        }
        private void calExP2(){
            for (int i = 0; i < this.listScore.Count; i++) {
                this.ExP2 = this.ExP2 + (this.listScore[i] * this.listScore[i]);
            }

            
        }

        private void CalEx2() {
            for (int i = 0; i < this.listScore.Count; i++ )
            {
                this.Ex2 = this.Ex2 + this.listScore[i];
            }
            this.Ex2 = (this.Ex2 * this.Ex2);
        }
    }
ตัวอย่างการเรียกใช้งาน
จากตัวอย่าง : http://www.stvc.ac.th/elearning/stat/csu3.html
//Ex2.จากข้อมูลต่อไปนี้จงหาส่วนเบี่ยงเบนมาตรฐาน 1, 2, 4, 6, 8, 9
            List listScore = new List();
            listScore.Add(1d);// 1, 2, 4, 6, 8, 9
            listScore.Add(2d);
            listScore.Add(4d);
            listScore.Add(6d);
            listScore.Add(8d);
            listScore.Add(9d);

            //1.การหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
            StandardDeviation sd = new StandardDeviation(listScore);
            Console.WriteLine("SD : "+ sd.Calculator());
            Console.ReadLine();
ผลการรันโปรแกรม

Read More