Translate

Silverlight Image Upload Using WCF service

Wednesday, March 19, 2014 Category : 0

step 1 :  add a class in your web service project with following details

[DataContract]
    public class FilesUploader
    {

        [DataMember]
        public string FileName { get; set; }

        [DataMember]
        public string FoldersName { get; set; }

        [DataMember]
        public byte[] Imagestream { get; set; }


    public string Upload(FilesUploader image)
        {
            FileStream fileStream = null;
            BinaryWriter writer = null;
            try
            {
                //filePath = HttpContext.Current.Server.MapPath(".") + ConfigurationManager.AppSettings["PictureUploadDirectory"] + image.ImageName;
                string location = ConfigurationManager.AppSettings["imageFileLocation"].ToString();
                string strFilePath = location + image.FoldersName + "\\" + image.FileName;
            
                if (image.FileName != string.Empty)
                {
                    fileStream = File.Open(strFilePath, FileMode.Create);
                    writer = new BinaryWriter(fileStream);
                    writer.Write(image.Imagestream);
                }
                return OperatioinResult.Success;
            }
            catch (Exception ex)
            {
                return OperatioinResult.ERROR + " ~ " + ex.Message;
            }
            finally
            {
                if (fileStream != null)
                    fileStream.Close();
                if (writer != null)
                    writer.Close();
            }
        }


}


step 2 : add this method in your service operation contracnt 

 [OperationContract]
        public string FilesUploader_UploadFiles(FilesUploader fileByte)
        {
            //MemoryStream byFile = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(fileByte));
            return new FilesUploader().Upload(fileByte);
        }


Step 3 : use this service reference in your silverlight clinet project.

           OpenFileDialog op = new OpenFileDialog();
           op.Filter = "Images (*.jpg, *.png, *.bmp)|*.jpg;*.png;*.bmp";
            op.ShowDialog();
            if (op.File != null && op.File.Name != "")
            {
                    fileStram = (FileStream)op.File.OpenRead();
                    byte[] bytes = new byte[fileStram.Length];
                    fileStram.Read(bytes, 0, (int)fileStram.Length);

                    FilesUploader fUploader = new FilesUploader();
                    tempImage = "tempPatientImages" + op.File.Extension;
                    fUploader.FileName = tempImage;
                    fUploader.Imagestream = bytes;
                    fUploader.FoldersName = "PatientImges";

                    service.FilesUploader_UploadFilesAsync(fUploader);
                    // service is the object of service provider you need it chage it to your object name.
}

Silverlight Combobox (static / dynamic) value get set

Tuesday, March 18, 2014 Category : 0

Static Data combobox


                    <ComboBox Grid.Column="3"
                              Grid.Row="7"
                              Name="cmbMariedStaus"
                              HorizontalAlignment="Left"
                              VerticalAlignment="Top"
                              Style="{StaticResource ComboboxEntryStyle}">

                        <ComboBox.Items>
                            <ComboBoxItem>Married</ComboBoxItem>
                            <ComboBoxItem>Un married</ComboBoxItem>
                        </ComboBox.Items>
                    </ComboBox>


Value GET :   (cmb.SelectedItem as ComboBoxItem).Content.ToString();
Value Set :   cmb.SelectedItem = cmb.Items.SingleOrDefault(c => (c as ComboBoxItem).Content.ToString() == values);

Dyanamic Data Combobox

<ComboBox Grid.Column="1"
                              Grid.Row="9"
                              Name="cmbDepartment"
                              ItemsSource="{Binding}"
                              HorizontalAlignment="Left"
                              VerticalAlignment="Top"
                              DisplayMemberPath="DepName"
                              SelectedValuePath="DepID"
                              Style="{StaticResource ComboboxEntryStyle}">
                    </ComboBox>

Value GET : cmbDepartment.SelectedValue.ToString();

Vale Set : cmbDepartment.SelectedValue = "some value";

SQL server attach a series of database using query

Wednesday, February 19, 2014 Category : 0

1 . step one
save all attach database name of you pc sql server using following command.

SELECT * FROM sys.master_files

Save the result to excel sheet.

now if you re-install your pc OS.


use the following. query for resotre all database. you may need some tuning to your database depend on the data found.




declare @dbName nvarchar(max)
declare @dbpath nvarchar(max)

declare dbc cursor for


-- Note F1 condition is used for escap some database . no need to attach those db
-- Note F2 condition is used to load only mdf file

select db_name,path from tablesm where F1>9 and F2=1


open dbc

fetch next from dbc into @dbName,@dbpath

while @@fetch_status = 0

begin

declare @logs nvarchar(max)

-- Note generating log file location from mdf file.
set @logs = substring(@dbpath,0,len(@dbpath)-3) + '.LDF'
--print @logs

declare @SQL  nvarchar(max)

set @SQL ='
CREATE DATABASE '+@dbName+'
 ON
( FILENAME = '''+@dbpath+''' ),
( FILENAME = '''+@logs+''' )
 FOR ATTACH
 '
--print @SQL
exec( @SQL)

fetch next from dbc into @dbName,@dbpath

end

close dbc
deallocate dbc

Microsoft sql server error : 5123 [Solved]

Category : 0

Access denied Error Solution :

open the properties of ldf and mdf file
1.  Check the owner ship status of mdf and ldf file.
2. Check if there a use call  Everyone user added to file group , if not found then added it to and give full permission.










1. if you have a lot file to do this operation you can do it using command prompt.


for taking ownership of all database or file of a directorry

D:
cd D:\SOL ServerDatabase2008\All
pause
takeown /f . /r
pause

save it and give extension of bat file and then execute using admin previlage


for add everyone user of a direcotry

icacls * /t  /grant Everyone:F
pause

must run on same directory




Unable to load one or more of the requested types. (C#)

Thursday, January 16, 2014 Category : 0

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Error was found : when we are developing an application using .net framework 4, on visual 2010, using entity framework, it works perfectly on local or devlopement pc.

but in clinet side it's not working. and give the above error. after trying lot of things we are able to discover soltion
if we change the reference properties behavious which we use in our project. it work

so the solution is

select the follwoing references 


  • System.Data.Entity
  • System.Web.Entity
and change the property of copy local to True. build the solution now, and now you will get those reference dll in your bin. and now problem will solve.

System.ComponentModel.Win32Exception: Access is denied Error [Solved]

Wednesday, January 15, 2014 Category : 0

IIS ExternalException (0x80004005): Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe 

Solution : Go to your application app pool . open advance settings. focus on Identity and then set your administrator privilege account. then restart app pool. and visit it again.


Sys.Extended is undefined (AjaxControlToolkit asp.net)

Tuesday, November 5, 2013 Category : 2

if u get this type 'Sys.Extended is undefined ' error in asp.net AjaxControlToolkit latest version on (4.1.7.1005)

use Ajaxtoolkit script manager not <asp:ScriptManager>

  <ajaxToolkit:ToolkitScriptManager EnablePartialRendering="true" runat="Server" ID="ScriptManager1" />




Powered by Blogger.