Anders
Anders

Reputation: 103

Retrieving info from gridview using deletebutton in commandfield

I have a gridview up and running. And I have a command field which deletes the record from my SQL Server. On my filesystem, I have all these image files.

I can not find (or I don't have a clue on how to search this specifically) any information on how to store the filename from the record itself, into a string in my code behind.

I want to use the command field delete button, and then store the "Filename" in a string at the same time. So I can run a stored procedure and then delete the file from my filesystem.

Any idea on how to store this information in a string?

Thanks in advance.

Upvotes: 0

Views: 64

Answers (1)

Tamal Kanti Dey
Tamal Kanti Dey

Reputation: 576

You can do like this:

public String [] readFile(String filePath){
        String [] lines=new String[1000];//Enough lines.
        int counter=0;
        try{
            File file = new File(filePath);//The path of the File
            FileReader fileReader1 = new FileReader(file);
            BufferedReader buffer = new BufferedReader(fileReader1);
            boolean flag=true;
            while(true){
                try{
                    lines[counter]=buffer.readLine();//Store a line in the array.
                    if(lines[counter]==null){//If there isn't any more lines.
                        buffer.close();
                        fileReader1.close();
                        break;//Stop reading and close the readers.
                    }
                    counter++;
                }catch(Exception ex){
                    break;
                }
            }
        }catch(FileNotFoundException ex){
            System.out.println("File not found.");
        }catch(IOException ex){
            System.out.println("Exception ocurred.");
        }
        return lines;
    }

or just another example;

List<string> s = new List<string>();
s.Add("c:\\documents and settings\\sound1.mp3");
s.Add("c:\\documents and settings\\sound2.mp3");

var mp3paths = s.Where(x => String.Compare(".mp3", Path.GetExtension(x), true) == 0);
var exepaths = s.Where(x => String.Compare(".exe", Path.GetExtension(x), true) == 0);

Hope this helps.

Upvotes: 0

Related Questions