2022年12月25日 星期日

ios系統影片mp4無法嵌入撥放問題

之前似乎也遇過,避免忘記MEMO一下。

撇除其他MIME、影片格式、靜音等問題後,用HTML5 video tag tag在WINDOWS瀏覽器沒問題,但在IOS系統上影片會無法撥放,查一下是得加上 playsinline 才可以正常撥放。

原因跟原理未知,之後有空研究再補說明吧(會有那天嗎XD

2022年11月14日 星期一

.NET VB 判斷DBNull的方法

DBNull不等於空值所以要用DBNull去判斷,紀錄一下每次都忘記的DBNull判斷方式


If Not 欄位 Is DBNull.Value Then 

-----

End If


If IsDBNull(欄位) Then

-----

End If

2022年7月13日 星期三

SQL排除條件參考

 SQL排除條件參考

https://stackoverflow.com/questions/17991479/insert-values-where-not-exists

2021年5月6日 星期四

網站繁簡切換

 目前看到最方便的方法,感謝前人的教學,文章連結:

https://www.wfublog.com/2014/12/traditional-simplified-chinese-auto-switch.html

2020年11月17日 星期二

.NET 基礎連接已關閉: 傳送時發生未預期的錯誤。

串接API時一直出現錯誤

基礎連接已關閉: 傳送時發生未預期的錯誤。

上網查找資料後應該是SSL的問題,總之就是串接方已經不接受TLS1.0的協定,所以要強制讓我方以TLS1.1或1.2

需.NET4.0以上,記得先Imports System.Net才能用參數

之後再整個Request前先加上

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

就可以解決了,未來會不會需要更新成更高或其他的協議就未知啦

2020年5月8日 星期五

把Base64 轉成 Byte Array 後儲存為圖檔

專案需要將撈出來的HTML頁面產生PDF...慢慢刻太花時間外加CSS很容易跑掉,乾脆轉圖檔儲存,但用html2canvas轉完後是base64,只好轉存成byte再save圖檔給PDF用...紀錄一下參考的base64 to byte文章
 
HTML Markup
The following HTML Markup consists of an ASP.Net FileUpload control to upload the Image File and a Button control to trigger the File upload process.
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
    onclick="btnUpload_Click" />
</form>
 
 
Convert Base64 string to Byte Array using C# and VB.Net
When the Upload button is clicked, the Image file is read into a Byte Array using the BinaryReader class object.
The Byte Array is then converted into Base64 encoded string using the Convert.ToBase64String method.
Now in order to save the Base64 encoded string as Image File, the Base64 encoded string is converted back to Byte Array using the Convert.FromBase64String function.
Finally the Byte Array is saved to Folder on Disk as File using WriteAllBytes method of the File class.
C#
protected void btnUpload_Click(object sender, EventArgs e)
{
    //***Convert Image File to Base64 Encoded string***//
 
    //Read the uploaded file using BinaryReader and convert it to Byte Array.
    BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream);
    byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length);
 
    //Convert the Byte Array to Base64 Encoded string.
    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
 
    //***Save Base64 Encoded string as Image File***//
 
    //Convert Base64 Encoded string to Byte Array.
    byte[] imageBytes = Convert.FromBase64String(base64String);
       
    //Save the Byte Array as Image File.
    string filePath = Server.MapPath("~/Files/" + Path.GetFileName(FileUpload1.PostedFile.FileName));
    File.WriteAllBytes(filePath, imageBytes);
}
 
VB.Net
Protected Sub btnUpload_Click(sender As Object, e As EventArgs)
    '***Convert Image File to Base64 Encoded string***
 
    'Read the uploaded file using BinaryReader and convert it to Byte Array.
    Dim br As New BinaryReader(FileUpload1.PostedFile.InputStream)
    Dim bytes As Byte() = br.ReadBytes(CInt(FileUpload1.PostedFile.InputStream.Length))
 
    'Convert the Byte Array to Base64 Encoded string.
    Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)
 
    '***Save Base64 Encoded string as Image File***
 
    'Convert Base64 Encoded string to Byte Array.
    Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
 
    'Save the Byte Array as Image File.
    Dim filePath As String = Server.MapPath("~/Files/" + Path.GetFileName(FileUpload1.PostedFile.FileName))
    File.WriteAllBytes(filePath, imageBytes)
End Sub
 

2020年3月23日 星期一

.Net VB 圖片上傳後變橫的

爬了下文應該是因為exif資訊的問題,上傳前必須先判斷是否需要轉角度...找了一下總算找到相關內容參考

Public Function TestRotate(sImageFilePath As String) As Boolean
    Dim rft As RotateFlipType = RotateFlipType.RotateNoneFlipNone
    Dim img As Bitmap = Image.FromFile(sImageFilePath)
    Dim properties As PropertyItem() = img.PropertyItems
    Dim bReturn As Boolean = False
    For Each p As PropertyItem In properties
      If p.Id = 274 Then
        Dim orientation As Short = BitConverter.ToInt16(p.Value, 0)
        Select Case orientation
          Case 1
            rft = RotateFlipType.RotateNoneFlipNone
          Case 3
            rft = RotateFlipType.Rotate180FlipNone
          Case 6
           rft = RotateFlipType.Rotate90FlipNone
          Case 8
           rft = RotateFlipType.Rotate270FlipNone
        End Select
      End If
    Next
    If rft <> RotateFlipType.RotateNoneFlipNone Then
      img.RotateFlip(rft)
      System.IO.File.Delete(sImageFilePath)
      img.Save(sImageFilePath, System.Drawing.Imaging.ImageFormat.Jpeg)
      bReturn = True
    End If
    Return bReturn

  End Function

需要import
System.Drawing
System.Drawing.Imaging

RotateFlipType還有很多種,但手機似乎只會遇到以上狀況所以就只用到1、3、6、8

感謝幫助到我的原文,那邊也有C#的寫法

原文網址點我

2020年3月5日 星期四

Null / DBNull / String.Empty的差異

找.net判斷null的東西時看到不錯的文章,但該文章已經失效只好自己紀錄一下...

以下是文章的紀錄:

Null跟DBNull及String.Empty這三者,或許很少有人認真的去想過這三者的差異在那,而什麼時候要用那一個去判斷?

從簡單的if去比對這三者是否相等,很快的就發現這三者是不相等的.

null != DBNull  /DBNull != string.Empty / null != string.Empty

那麼現在宣告了兩個變數,一個是string a="",另一個是string b=null; 那麼這兩個變數是各自符合那一種?

結果是

a != null;

a != DBNull

a = string.Empty

拿.Net 2.0才有的新判斷string.IsNullOrEmpty來看.也是為true

而b的部份則如下

b = null

b != dbnull

b != string.Empty

string.IsNullOrEmpty(b) = true

從這兩個例子看到什麼時候是Null,什麼時候是string.Empty,那麼DBNull呢?

DBNull的使用時機,當至資料庫查詢,符合的資料回傳的資料欄位沒有值,為null時,此時此欄位的值就=DBNull.

當至資料庫查詢,沒有符合的資料回傳時,此時回傳的結果就=Null.



Null是當物件未被初始化時的情況,例如 StreamReader reader;還沒有給new StreamReader();

ex :
object o=cmd.ExecuteScalar();(回傳一個欄位的值)
狀況1:當DB回傳有符合的資料,但該欄位沒有值時.o = DBNull 可是 o != null
狀況2:當DB回傳沒有符合的資料時, o = null可是o != DBNull
狀況3:不論是狀況1或狀況2的結果,Convert.ToString(o)=string.Empty;


感謝原作者的文章,雖然連結已失效還是貼下
https://www.dotblogs.com.tw/jeff-yeh/archive/2008/12/07/6286.aspx

2019年12月11日 星期三

FileUpload控制項批次上傳範例

找批次上傳的參考時的筆記,紀錄一下,要 .NET版本4.5才能用...


參考網址:
https://dotblogs.com.tw/mis2000lab/2012/04/26/net45_fileupload_allowmultiple



HTML畫面設計:
      注意!!只有一個 FileUpload控制項而已。
                      它的 AllowMultiple屬性已經啟動!



VB語法,範例如下:
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        '--註解:網站上的目錄路徑。所以不寫磁碟名稱(不寫 “實體”路徑)。
        '--           上傳後的存檔目錄,請依照您的環境作修改。

        Dim saveDir As String = "\[Book]FileUpload\Uploads\"
        Dim appPath As String = Request.PhysicalApplicationPath

        Dim tempfileName As String = Nothing
        Dim myLabel As New System.Text.StringBuilder

        '===========================================
        '== Ony .NET 4.5有這個新的 AllowMultiPle屬性
        '===========================================


        Dim fileName, savePath As String
        For Each postedFile As HttpPostedFile In FileUpload1.PostedFiles
            fileName = postedFile.FileName

            ' –完成檔案上傳的動作。
            savePath = appPath & saveDir & fileName
            postedFile.SaveAs(savePath)

            myLabel.Append("<hr>檔名---- " & fileName)

        Next

        Label1.Text = "上傳成功" & myLabel.ToString()
    End Sub





2019年11月24日 星期日

.net vb 排除特定符號字元

需要阻擋透過表單傳遞惡意傳遞sql或其他指令,本想用正則表達式但考慮到email跟一些使用者可能使用的符號所以還是作罷,最後用比對方式處理,紀錄一下參考資料

VB.NET code

Public Class Form3
    Private ReadOnly InvalidChars As String = "[" + System.Text.RegularExpressions.Regex.Replace(""";&^%$#", ".", "\$&") + "]"
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String = "有特殊字符哦"
        If System.Text.RegularExpressions.Regex.Match(s, InvalidChars).Success Then
            MessageBox.Show("有特殊字符")
        Else
            MessageBox.Show("没有特殊字符")
        End If
    End Sub
End Class

參考網址:

2019年2月10日 星期日

.NET跟IIS的上傳限制設定

更新版本後的IIS以前的寫法沒用了,網路上找到的方法引用來memo當筆記

ASP.net File Upload Size

前言

從IIS7開始,IIS預設限制28MB左右的要求內容長度,而ASP.net預設則是限制4MB大小
如果一個網站的用戶想上傳100MB檔案,勢必IIS和ASP.net兩邊都要設定

實作

ASP.net Web.config裡寫下以下區段
<system.web>
 <httpRuntime  maxRequestLength="102400" executionTimeout="600"/>
</system.web>
maxRequestLength 檔案大小(KB),預設值4096 KB(4MB),所以102400KB為100MB
executionTimeout 上傳時間(秒),600秒為10分鐘
<system.webServer>
 <security>
  <requestFiltering>
   <requestLimits maxAllowedContentLength="104857600" />
  </requestFiltering>
 </security>
</system.webServer>
maxAllowedContentLength 檔案大小(byte),所以104857600(1024*1024*100)為100MB
上述system.webServer也可以透過IIS來設定
允許的內容長度上限預設值為30000000(約28MB),把它修改為104857600

如此一來,網站便可以上傳100MB大小的檔案了

加碼補充

如果當使用者上傳檔案超過限制大小時,想重新導向到自訂的錯誤頁面
在Global.asax.cs裡寫下...
protected void Application_BeginRequest(object sender, EventArgs e)
{
 HttpRuntimeSection section = (HttpRuntimeSection)ConfigurationManager.GetSection("system.web/httpRuntime");
 int maxFileSize = section.MaxRequestLength * 1024;
 if (Request.ContentLength > maxFileSize)
 {
  try
  {
   Response.Redirect("~/MySizeError.aspx");
  }
  catch (Exception ex)
  {
   
  }
 }
}


引用來源:高級打字員的技術雲

2018年8月1日 星期三

解決瀏覽器暫存網頁無法自動更新css檔案問題

瀏覽器暫存會讓網站的css檔案無法即時更新,雖然強制重整就能解決但如果用手機觀看除非清除資料不然只能等暫存更新時間才能更新,為了讓客戶可以即時看到修改乾脆在css檔案的路徑後方加上亂數,這樣瀏覽器就會以為是不同檔案重抓css了


.net vb
<link href="Style.css?v=<%=now()%>" rel="stylesheet" type="text/css">

懶得建立亂數乾脆用當下時間了,缺點是使用者會一直下載Cache檔案 XDDD


2018年6月14日 星期四

IIS7.5 , 8版本檔案上傳限制、時間處理(上傳檔案後出現404)

伺服器更新後用IIS7.5版本發現客戶上傳檔案時會跑出404錯誤,找了一下文章大部分都說加入下面這串就可以解決


但實際加上後發現因為位置或原本的設置很容易出現 500 - Internal server error. 的錯誤,後來終於找到從IIS直接設定的方法 ,步驟如下:

1.先到IIS選取要設定網站後進入設定編輯器

2.設置上傳超時時間限制:
點擊下拉選單,選system.web>httpRuntime
將executionTimeout的值設為00:30:00(30分鐘)

3.設置上傳文件大小限制:
點擊下拉選單,選system.webServer>security>requestFiltering
展開requestlimits,將maxAllowedContentLength的值設為102400000(即100MB,可設定更大,最大印象中是4GB)

修改後就會生效,不需重啟IIS。

如果需要圖文說明可以到下方參考連結看

2017年12月6日 星期三

[VB]將讀出的資料去除HTML標籤方法

利用客戶輸入的資料來當fb的描述時發現必須把html標籤去除...

網路上找到了個function不錯用,紀錄一下


Public Function splitHTML(ByVal Html As String) As String
    Dim split As String = Html
    Dim Regex As New System.Text.RegularExpressions.Regex("<[^>]+>|]+>")
    split = Regex.Replace(split, "")
    Return split
End Function

來源:https://dotblogs.com.tw/joysdw12/2010/11/11/19379

2016年10月11日 星期二

CORDOVA打包APP的cookie問題


用cordova打包html+js成APP時發現android不能存取cookie..找到下面文章參考解決

該檔案位置似乎版本不同不一定在那?

我的位置是在專案底下的"\platforms\android\src\io\cordova"裡面有個資料夾打開就會看到。

另外要注意的是修改好該檔案後存檔完記得關閉,不然再打包途中會出現說該檔案已修改..之後打包出來的APP會有些BUG跟問題...

用jquery的cookie也適用此方法。

參考網址:http://aubreyhsu.blogspot.tw/2015/05/documentcookie-dont-work-in-android.html

在利用cordova打包html和js時,發現document.cookie竟然寫不進手機裡,查資料才知道在android 3.1以上需要打開cookie寫入,操作如下:
1、打開專案底下的「\platforms\android\src\com\example\MainActivity.java」:
2、先「import android.webkit.CookieManager;」,
3、在 onCreate function裡面「CookieManager.setAcceptFileSchemeCookies(true);

範例如下:
import android.os.Bundle;
import android.webkit.CookieManager;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        CookieManager.setAcceptFileSchemeCookies(true);
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}

2016年9月22日 星期四

建立給apk使用的金鑰

公司需求開始開發app的東西..做了apk之後安裝發現得產生金鑰來使用..所以找了些文章參考..

大概整理一下如下:
以下資料參考來源:https://taco.visualstudio.com/en-us/docs/tutorial-package-publish-readme/ 

Generate a private key

To sign your app, create a keystore. A keystore is a binary file that contains a set of private keys. Here's how you create one.
  1. Open a Command Prompt in administrator mode.
  2. In the Command Prompt, change directories to the %JAVA_HOME%\bin folder.
    (For example: C:\Program Files (x86)\Java\jdk1.7.0_55\bin).
  3. In the Command Prompt, run the following command.
    keytool -genkey -v -keystore c:\my-release-key.keystore -alias johnS
    -keyalg RSA -keysize 2048 -validity 10000
    
    Replace my-release-key.keystore and johnS with names that make sense to you.
  4. You'll be asked to provide a password and the Distinguished Name fields for your key.
    This series of responses gives you an idea of the kinds of information you'll provide for each prompt. Like in the previous command, respond to each prompt with information that makes sense for your app.
    Enter keystore password: pwd123
    Re-enter new password: pwd123
    What is your first and last name?
    [Unknown]= John Smith
    What is the name of your organizational unit?
    [Unknown]= ABC
    What is the name of your organization?
    [Unknown]= XYZ
    What is the name of your of your City or Locality?
    [Unknown]= Redmond
    What is the name of your State or Province?
    [Unknown]= WA
    What is the two-letter country code for this unit?
    [Unknown]= US
    Is CN=John Smith, OU=ABC, O=XYZ, L=Redmond, ST=WA, C=US correct??
    [no]=  y
    
    
    After you provide this information, output like this appears in the Command Prompt.
    Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA)
    with a validity of 10,000 days for: CN= John Smith, OU= ABC, O= XYZ,
    L=Redmond, ST=WA, C=US
    
    Enter key password for <johnS>
        (RETURN if same as keystore password):
    
    The Android SDK generates the keystore as a file named my-release-key.keystore and places that file in the C:\ drive. The keystore contains a single key, valid for 10000 days.
    If you want more detail about this process, see the Android developer documentation here:Signing your applications

照以上步驟後會產生一個key在你指定的位置,之後到apk原碼的資料夾中應該有一個build.json的檔案,打開後把裡面分別照自己設定的填入,照上方範例的話就是

{
 "android": {
     "release": {
         "keystore":"c:\\my-release-key.keystore",
         "storePassword":"pwd123",
         "alias":"johnS",
         "password":"pwd123",
         "keystoreType":""
       }
   }
}
之後打包後安裝就沒金鑰問題了。

2016年5月16日 星期一

CheckBox全選或全不選

找看看如何實作核選方塊的全選與全取消功能時剛好翻到這方法,很簡單就能處理。

原文章可運行測試:
http://www.wowbox.com.tw/blog/article.asp?id=2923

程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CheckBox全選或全不選</title>
<style type="text/css">
p {margin:0;font-size:12px;line-height:26px;}
</style>
<script type="text/javascript">
function check_all(obj,cName)
{
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
}
</script>
</head>
 
<body>
<p><input type="checkbox" name="all" onclick="check_all(this,'c')" />全選/全不選</p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
</body>
</html>

2015年10月16日 星期五

不需js的漸變效果(可套用到滿版div)

雖然沒有箭頭或任何點擊來作用換圖,但很簡單就能讓手機電腦都能使用的輪播,而且配合做好的滿版div可以輕鬆實現滿版輪播效果!

資料來源:http://blog.shihshih.com/pure-css-slider/


Step 1:先將圖片就定位

HTML Markup


<divdiv class="slider_container">
    <divdiv>
        <divimg src="images/image1.png" alt="pure css3 slider" />
        <divspan class="info">Image Description
    <div/div>
    <divdiv>
        <divimg src="images/image2.png" alt="pure css3 slider" />
        <divspan class="info">Image Description
    <div/div>
    <divdiv>
        <divimg src="images/image3.png" alt="pure css3 slider" />
        <divspan class="info">Image Description
    <div/div>
    <divdiv>
        <divimg src="images/image4.png" alt="pure css3 slider" />
        <divspan class="info">Image Description
    <div/div>
    <divdiv>
        <divimg src="images/image5.png" alt="pure css3 slider" />
        <divspan class="info">Image Description
    <div/div>
<div/div>

CSS Style


.slider_container {
    margin: 30px auto;
    width: 400px;
    height: 280px;
    position: relative;
    border: 20px solid;    
    border-color: #fff;
    border-bottom-width: 100px;
    background-color: #f5f5f5;
    box-shadow: #666 0 0 5px;
}

.slider_container div {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    filter: alpha(opacity=0);
}

Step 2:確認輪播效果的時間軸

先決定過場時間(前後兩張圖片重疊的時間)、每張圖片播放的時間、完成一個週期需要多少時間。
pure css3 slider
由上圖我們知道我們的輪播器共有5張圖片,過場時間為1秒、每張圖片播放4秒、一個完整的週期是25秒。因為@keyframe的時間是以百分比來表示,因為我們要先把秒換成百分比。
100% / 25秒 = 4% ( 每秒)
4% = 1秒

CSS3 Keyframes Animation

設定動畫週期。

.slider_container div {
    -webkit-animation: round 25s linear infinite;
            animation: round 25s linear infinite;
}

@-webkit-keyframes round {
    4% {
        opacity: 1;
        filter: alpha(opacity=100);
        /* 0 - 1秒 淡入*/
    }
    20% {
        opacity: 1;
        filter: alpha(opacity=100);
        /* 1- 5秒靜止*/
    }
    24% {
        opacity: 0;
        filter: alpha(opacity=0);
        /* 5-6秒淡出*/
    }
}
@keyframes round {
    4% {
        opacity: 1;
        filter: alpha(opacity=100);
        /* 0 - 1秒 淡入*/
    }
    20% {
        opacity: 1;
        filter: alpha(opacity=100);
        /* 1- 5秒靜止*/
    }
    24% {
        opacity: 0;
        filter: alpha(opacity=0);
        /* 5-6秒淡出*/
    }
}
每張圖片進場時間相隔5秒

.slider_container div:nth-child(5) {
    -webkit-animation-delay: 0s;
            animation-delay: 0s;
}

.slider_container div:nth-child(4) {
    -webkit-animation-delay: 5s;
            animation-delay: 5s;
}

.slider_container div:nth-child(3) {
    -webkit-animation-delay: 10s;
            animation-delay: 10s;
}

.slider_container div:nth-child(2) {
    -webkit-animation-delay: 15s;
            animation-delay: 15s;
}

.slider_container div:nth-child(1) {
    -webkit-animation-delay: 20s;
            animation-delay: 20s;
}
CSS transition
當滑鼠移到圖片上時、底下出現 “Image Description" 字樣且輪播動畫暫停。當滑鼠離開時、"Image Description" 字樣且輪播動畫繼續播放。

.slider_container span {    
    color: #000;
    background: #fff;
    position: absolute;
    left: 0%;
    top: 280px;
    width: 400px;
    height: 100px;
    font-size: 30px;
    text-align: center;
    line-height: 100px;
    -webkit-transform:scaleY(0);
        -ms-transform:scaleY(0);
            transform:scaleY(0);
    -webkit-transition: all 0.5s ease-in-out;
            transition: all 0.5s ease-in-out;
}

.slider_container:hover span {
    width: 100%;
    -webkit-transform:scaleY(1);
        -ms-transform:scaleY(1);
            transform:scaleY(1);
}
Pause And Restart
當滑鼠移到圖片上時,暫停播放動畫。

.slider_container:hover div {
    -webkit-animation-play-state: paused;
            animation-play-state: paused;
}