|  | 
	                
  
    |  |  
    | 
        
        ถามเกี่ยวกับการ create textfile บน desktop กับ ie mobile ค่ะ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | เขียน code เพื่อสร้าง textfile ดังนี้ค่ะ พอรันบน เครื่อง desktop สามารถสร้างได้ไม่มีปัญหาอะไรค่ะ โดยใน txtsaveto.Text กรอกเป็น C:\Folder\
 
 แต่ปัญหาคือว่าถ้าใช้ IE Mobile เปิดหน้านี้ขึ้นมาแล้วต้องการสร้าง textfile มัน Error น่ะค่ะ
 โดยใน txtsaveto.Text กรอกเป็น \Storage Card\mSET\ (ใน Mobile Phone จะไม่มีการระบุ drive เขาจะมีแค่ device กับ storage card ค่ะ)
 
 ปัญหาคือ แล้วจะระบุไดร์ฟ หรือให้มันหาไดร์ฟหรือ  path  ที่ระบุ \Storage Card\mSET\  ได้ยังไงอ่ะคะ
 หรือว่าการเขียนคำสั่งต่างๆ ที่เขียนมา สำหรับเครื่อง desktop กับ ie mobile จะไม่เหมือนกันคะ
 
 Code (VB.NET)
 
  Private Sub WRITEFILESALES()
        Dim dt As New DataTable
        Dim strQ As String = ""
        strQ = "SELECT * FROM SALES WHERE RouteNo=" & Session.Contents("irouteno") & ""
        dt = GetData(strQ, "SALES.mdb")
        If dt.Rows.Count <= 0 Then
            Response.Write("<script language='javascript'>window.alert('ไม่มีข้อมูล!');</script>")
            Return
        End If
        Dim sw As StreamWriter
        'Dim isoStorage As IsolatedStorage.IsolatedStorageFile
        ''isoStorage = IsolatedStorage.IsolatedStorageFile.GetUserStoreForDomain
        'isoStorage = IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication
        ''Dim writer As New  (stmWriter, Encoding.UTF8)
        'Dim sw As New IsolatedStorage.IsolatedStorageFileStream(Session.Contents("irouteno") & "Sales.txt", _
        '    FileMode.Create, isoStorage)
        'Dim writer As New System.Xml.XmlTextWriter(sw, Encoding.UTF8)
        If File.Exists(txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt") Then
            Response.Write("<script language='javascript'>window.alert('ชื่อไฟล์ซ้ำมีไฟล์ชื่อนี้อยู่แล้ว!');</script>")
            Return
        Else
            sw = File.CreateText(txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt")
        End If
        Dim line As String = ""
        Try
            Dim SalesDate As String
            Dim RouteNo As String
            Dim InvNo As String
            Dim BookNo As String
            Dim CustCode As String
            Dim AmphorCode As String
            Dim BILLITEM As String
            Dim StockGroup As String
            Dim SHCode As String
            Dim Qty As String
            Dim Discount As String
            Dim Amount As String
            Dim PriceBig As String
            Dim PriceSmall As String
            Dim PVAT As String
            Dim LastUpdate As String
            Dim LastUser As String
            For i As Integer = 0 To dt.Rows.Count - 1
                SalesDate = CheckNull(dt.Rows(i).Item("SalesDate")) '8
                RouteNo = CheckNull(dt.Rows(i).Item("RouteNo")) '3
                InvNo = CheckNull(dt.Rows(i).Item("InvNo")) '6
                BookNo = CheckNull(dt.Rows(i).Item("BookNo")) '2
                CustCode = CheckNull(dt.Rows(i).Item("CustCode")) '8
                AmphorCode = CheckNull(dt.Rows(i).Item("AmphorCode")) '4
                BILLITEM = CheckNull(dt.Rows(i).Item("BILLITEM")) '3
                StockGroup = CheckNull(dt.Rows(i).Item("StockGroup"))  '4
                SHCode = CheckNull(dt.Rows(i).Item("SHCode")) '7
                Qty = CheckNull(dt.Rows(i).Item("Qty")) '7
                Discount = CheckNull(dt.Rows(i).Item("Discount")) '12
                Amount = CheckNull(dt.Rows(i).Item("Amount")) '12
                PriceBig = CheckNull(dt.Rows(i).Item("PriceBig")) '12
                PriceSmall = CheckNull(dt.Rows(i).Item("PriceSmall")) '12
                PVAT = CheckNull(dt.Rows(i).Item("PVAT")) '7
                LastUpdate = CheckNull(dt.Rows(i).Item("LastUpdate")) '13
                LastUser = CheckNull(dt.Rows(i).Item("LastUser")) '10
                line = SalesDate.PadRight(8, "") & RouteNo.PadRight(3, "") & _
                InvNo.PadRight(6, "") & BookNo.PadRight(2, "") & _
                CustCode.PadRight(8, "") & AmphorCode.PadRight(4, "") & _
                BILLITEM.PadRight(3, "") & StockGroup.PadRight(4, "") & _
                SHCode.PadLeft(7, "0") & Qty.PadLeft(7, "0") & _
                Discount.PadLeft(12, "0") & Amount.PadLeft(12, "0") & _
                PriceBig.PadLeft(12, "0") & PriceSmall.PadLeft(12, "0") & _
                PVAT.PadLeft(7, "0") & LastUpdate.PadRight(13, "") & _
                LastUser.PadRight(10, "")
                sw.WriteLine(line) ' change padding parameter accordingly!
            Next
            sw.WriteLine("EOD")
            dt.Dispose()
            sw.Close()
            Response.Write("<script language='javascript'>window.alert('ดาวน์โหลดข้อมูลเรียบร้อย');</script>")
        Catch ex As Exception
            Response.Write("<script language='javascript'>window.alert('ไม่สามารถดาวน์โหลดข้อมูลได้!');</script>")
            Exit Sub
        End Try
    End Sub
  
 
 
 Tag : .NET
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2010-08-03 22:27:00 | By :
                          njnight | View :
                          1497 | Reply :
                          6 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (C#) 
 using System;
using System.IO;
using System.Runtime.InteropServices;
namespace StorageCardInfo
{
    class Program
    {
        const ulong Megabyte = 1048576;
        const ulong Gigabyte = 1073741824;
        [DllImport("CoreDLL")]
        static extern int GetDiskFreeSpaceEx(
        string DirectoryName,
        out ulong lpFreeBytesAvailableToCaller,
        out ulong lpTotalNumberOfBytes,
        out ulong lpTotalNumberOfFreeBytes 
    );
    static void Main(string[] args)
    {
        DirectoryInfo root = new DirectoryInfo("\\");
        DirectoryInfo[] directoryList = root.GetDirectories();
        ulong FreeBytesAvailable;
        ulong TotalCapacity;
        ulong TotalFreeBytes;
        for (int i = 0; i < directoryList.Length; ++i)
        {
            if ((directoryList.Attributes & FileAttributes.Temporary) != 0)
            {
                GetDiskFreeSpaceEx(directoryList.FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);
                Console.Out.WriteLine("Storage card name: {0}", directoryList.FullName);
                Console.Out.WriteLine("Available Bytes : {0}", FreeBytesAvailable);
                Console.Out.WriteLine("Total Capacity : {0}", TotalCapacity);
                Console.Out.WriteLine("Total Free Bytes : {0}", TotalFreeBytes);
            }
        }
    }
}
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-03 22:41:38 | By :
                            ... |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุณค่ะ 
 จะลองทำดูนะคะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-03 23:49:14 | By :
                            njnight |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | แก้ไขแล้วก็ยัง Error แบบนี้ค่ะ 
 Code (VB.NET)
 
 Private Sub WRITEFILESALES()
        Dim dt As New DataTable
        Dim strQ As String = ""
        strQ = "SELECT * FROM SALES WHERE RouteNo=" & Session.Contents("irouteno") & ""
        dt = GetData(strQ, "SALES.mdb")
        If dt.Rows.Count <= 0 Then
            Response.Write("<script language='javascript'>window.alert('ไม่มีข้อมูล!');</script>")
            Return
        End If
        '==============================================
        Dim rootDir As DirectoryInfo = New DirectoryInfo("\")
        Dim attrStorageCard As FileAttributes = (FileAttributes.Directory Or FileAttributes.Temporary)
        Dim fsi As FileSystemInfo
        Dim strpath As String = ""
        For Each fsi In rootDir.GetFileSystemInfos()
            Dim n As Integer = fsi.FullName.IndexOf("\")
            strpath = fsi.FullName.Substring(0, n)
        Next
        Dim sw As StreamWriter
        If File.Exists(strpath + txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt") Then
            Response.Write("<script language='javascript'>window.alert('ชื่อไฟล์ซ้ำมีไฟล์ชื่อนี้อยู่แล้ว!');</script>")
            Return
        Else
            sw = File.CreateText(strpath + txtsaveto.Text.Trim & Session.Contents("irouteno") & "Sales.txt")
        End If
        Dim line As String = ""
        Try
            Dim SalesDate As String
            Dim RouteNo As String
            Dim InvNo As String
            Dim BookNo As String
            Dim CustCode As String
            Dim AmphorCode As String
            Dim BILLITEM As String
            Dim StockGroup As String
            Dim SHCode As String
            Dim Qty As String
            Dim Discount As String
            Dim Amount As String
            Dim PriceBig As String
            Dim PriceSmall As String
            Dim PVAT As String
            Dim LastUpdate As String
            Dim LastUser As String
            For i As Integer = 0 To dt.Rows.Count - 1
                SalesDate = CheckNull(dt.Rows(i).Item("SalesDate")) '8
                RouteNo = CheckNull(dt.Rows(i).Item("RouteNo")) '3
                InvNo = CheckNull(dt.Rows(i).Item("InvNo")) '6
                BookNo = CheckNull(dt.Rows(i).Item("BookNo")) '2
                CustCode = CheckNull(dt.Rows(i).Item("CustCode")) '8
                AmphorCode = CheckNull(dt.Rows(i).Item("AmphorCode")) '4
                BILLITEM = CheckNull(dt.Rows(i).Item("BILLITEM")) '3
                StockGroup = CheckNull(dt.Rows(i).Item("StockGroup"))  '4
                SHCode = CheckNull(dt.Rows(i).Item("SHCode")) '7
                Qty = CheckNull(dt.Rows(i).Item("Qty")) '7
                Discount = CheckNull(dt.Rows(i).Item("Discount")) '12
                Amount = CheckNull(dt.Rows(i).Item("Amount")) '12
                PriceBig = CheckNull(dt.Rows(i).Item("PriceBig")) '12
                PriceSmall = CheckNull(dt.Rows(i).Item("PriceSmall")) '12
                PVAT = CheckNull(dt.Rows(i).Item("PVAT")) '7
                LastUpdate = CheckNull(dt.Rows(i).Item("LastUpdate")) '13
                LastUser = CheckNull(dt.Rows(i).Item("LastUser")) '10
                line = SalesDate.PadRight(8, "") & RouteNo.PadRight(3, "") & _
                InvNo.PadRight(6, "") & BookNo.PadRight(2, "") & _
                CustCode.PadRight(8, "") & AmphorCode.PadRight(4, "") & _
                BILLITEM.PadRight(3, "") & StockGroup.PadRight(4, "") & _
                SHCode.PadLeft(7, "0") & Qty.PadLeft(7, "0") & _
                Discount.PadLeft(12, "0") & Amount.PadLeft(12, "0") & _
                PriceBig.PadLeft(12, "0") & PriceSmall.PadLeft(12, "0") & _
                PVAT.PadLeft(7, "0") & LastUpdate.PadRight(13, "") & _
                LastUser.PadRight(10, "")
                sw.WriteLine(line)
            Next
            sw.WriteLine("EOD")
            dt.Dispose()
            sw.Close()
        Catch ex As Exception
            Response.Write("<script language='javascript'>window.alert('ไม่สามารถดาวน์โหลดข้อมูลได้!');</script>")
            Exit Sub
        End Try
    End Sub
 
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-04 13:57:12 | By :
                            njnight |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | (ไม่เคยเขียนนะ .net) 
 ดูจาก exception แล้วมันบอกว่า ไม่มีสิทธิ์เข้าถึง
 เดาว่าต้องหาวิธีได้สิทธิ์มาก่อน
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-04 14:08:03 | By :
                            pjgunner |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ใช่ค่ะเราก็คิดว่าติดเรื่องสิทธิ์ สงสัยจะชี้พาท ไปผิดที่ เพราะถ้าดาวน์โหลดลงในมือถือ user เองไม่น่าจะติดเรื่องสิทธิ์ได้ 
 Code (VB.NET)
 
  '==============================================
        Dim rootDir As DirectoryInfo = New DirectoryInfo("\")
        Dim attrStorageCard As FileAttributes = (FileAttributes.Directory Or FileAttributes.Temporary)
        Dim fsi As FileSystemInfo
        Dim strpath As String = ""
        For Each fsi In rootDir.GetFileSystemInfos()
            Dim n As Integer = fsi.FullName.IndexOf("\")
            strpath = fsi.FullName.Substring(0, n)
        Next
 คิดว่ามันชี้ไปที่ ไดร์ฟ ที่ แอพลิเคชั่นอยู่หรือเปล่าคะ
 
 ต้องการให้มันหาชื่อ storage drive เพื่่อสร้างเท็กไฟล์บนมือถือ ทำยังไงคะ ยังแก้ไม่ได้เลย
 
 ใครก็ได้ช่วยหน่อยนะคะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-05 23:01:42 | By :
                            njnight |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ช่วยด้วยค่าา แงๆๆ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-06 09:45:21 | By :
                            njnight |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |