Windows Phone 82012. 12. 10. 12:35

 

일단 저장부터 ㅋ

private async Task FileSave(MemoryStream stream)
     {
         IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
         IStorageFile storageFile = await applicationFolder.CreateFileAsync(Const.LocalPlaylistFileName, CreationCollisionOption.ReplaceExisting);
         using (Stream fileStream = await storageFile.OpenStreamForWriteAsync())
         {                
             stream.Seek(0, SeekOrigin.Begin);
             await stream.CopyToAsync(fileStream);
             await fileStream.FlushAsync();
             stream.Dispose();
         }

 

로드하는부분

public async Task LoadAlbums()
       {
         
           IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
 
           IStorageFile storageFile = await applicationFolder.GetFileAsync(Const.LocalPlaylistFileName);
 
           IRandomAccessStream accessStream = await storageFile.OpenReadAsync();
 
           using (Stream stream = accessStream.AsStreamForRead((int)accessStream.Size))
           {
               var o = _serializer.ReadObject(stream);
               LocalPlaylist = o as ObservableCollection<LocalMyAlbum>;
           }
       }

 

일단 윈7이랑 조금 달라졌다.

 

참조한곳이랑은 약간 다르게 구현~

 

참고한곳 : http://dotnetapp.com/blog/2012/08/02/windows-phone-8-shared-core-with-windows-8-file-io/

Posted by 동동(이재동)
wcf2011. 6. 16. 11:55

일단 WCF에서 보자

[WebInvoke(UriTemplate = "FileUpload?FileName={fileName}", Method = "PUT")]
       public void FileUpLoad(string fileName, Stream fileStream)
       {
           FileStream fileToupload = new FileStream("d:\\" + fileName, FileMode.Create);
 
           byte[] byteArray = new byte[10000];
           int byteRead, totalByteRead = 0;
           do
           {
               byteRead = fileStream.Read(byteArray, 0, byteArray.Length);
               totalByteRead += byteRead;
           } while (byteRead > 0);
 
           fileToupload.Write(byteArray, 0, byteArray.Length);
           fileToupload.Close();
           fileToupload.Dispose();
       }

 

일단 이렇게 메소드를 작성해서 file 이름과 stream을 받아서 파일을 경로에 쓴다.

 

method는 put으로 한다.

 

자 이제 끝이다. 이제 WPF에서 호출해보자.

 

 

 

public void ImageUpload(string fileName, string filePath)
        {
            using (WebClient webclient = new WebClient())
            {
                webclient.UploadData(new Uri(string.Format(serverUri + "/FileUpload?FileName={0}",fileName)), "put", GetData(filePath));
            }
        }
 
        private byte[] GetData(string filePath)
        {
            FileStream stream = File.OpenRead(filePath);
 
            byte[] data = new byte[stream.Length];
 
            stream.Read(data, 0, data.Length);
 
            stream.Close();
 
            return data;
        }

 

이렇게 filename과 byte로 변환된 스트림을 WCF로 날려주기만 하면 된다.

Posted by 동동(이재동)
좋은 프로그램2011. 3. 8. 09:42

인덱싱 해서 하는것인줄 알았는데 아닌거 같다.


바로 찾아진다. ㄷㄷㄷ


Everything search engine

http://www.voidtools.com/

Posted by 동동(이재동)