Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to call the code?

Posted on 2014-07-29
9
166 Views
Last Modified: 2014-07-29
I have a class file in my solution GetFile.cs
In here is a function called CopyFile()

In order to test CopyFile() I added a webform to the solution and in the page_load event in the code behind I am trying to call CopyFile() but no matter how I try intellisense is not offering it up.
I have tried CopyFile() and I have tried creating a new instance of GetFile as below but still I can't "reach" it

 public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetFile theFile = new GetFile();

Open in new window


Here is CopyFile()

namespace HubbleDocs
{
    public class GetFile
    {

        
        public void CopyFile()
        {
...
}

Open in new window

0
Comment
Question by:QPR
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40228210
Add a using statement to the top of your _default class:

using HubbleDocs;

Open in new window

0
 
LVL 29

Author Comment

by:QPR
ID: 40228221
Sorry I should have posted the whole of default.aspx.cs as I already have that using statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HubbleDocs;

namespace HubbleDocs
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetFile theFile = new GetFile();
            
        }
    }
}

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40228227
Is GetFile defined with the same assembly (i.e. project)?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 29

Author Comment

by:QPR
ID: 40228232
Yep, solution/project is called HubbleDocs which consists of GetFile.cs and default.aspx/cs (and a web service reference)
0
 
LVL 29

Author Comment

by:QPR
ID: 40228237
solution files
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40228254
Is it possible to post the entire GetFile definition?
0
 
LVL 29

Author Comment

by:QPR
ID: 40228258
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;


namespace HubbleDocs
{
    public class GetFile
    {

        
        public void CopyFile()
        {
            string webUrl = "http://xxx";
            FileCopy.Copy copyService = new FileCopy.Copy();
            copyService.Url = webUrl +"/_vti_bin/copy.asmx";
            NetworkCredential m_credentials = new NetworkCredential("x", "x", "x");
                 copyService.Credentials = m_credentials;

            //Source and Destination Document URLs
             string sourceUrl = "http://xxx/Documents/Sample.docx";
             string destinationUrl = "C:\\Documents\\Sample.doc";

            //Variables for Reading metadata’s of a document
             FileCopy.FieldInformation fieldInfo = new FileCopy.FieldInformation();
             FileCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
             FileCopy.CopyResult cResult1 = new FileCopy.CopyResult();
             FileCopy.CopyResult cResult2 = new FileCopy.CopyResult();
             FileCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        

            //Receive a Document Contents  into Byte array (filecontents)
             byte[] fileContent; // no need to initialize the GetItem takes care of that.
             copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContent);

            //Create a new file and write contents to that document
             FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
            fStream.Write(fileContent, 0, fileContent.Length);
            fStream.Close();
        }
    }
}

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40228271
Based on what you've posted, I don't see anything wrong. You should only have to invoke against the instance.

e.g.

GetFile theFile = new GetFile();

theFile.CopyFile();

Open in new window

0
 
LVL 29

Author Comment

by:QPR
ID: 40228276
and now that I type it again I see it and it works!
So either my tired eyes didn't see it in the intellisense or the intellisense hadn't refreshed.
Oh well - all good now :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET(C#) Eliminating weekends from a date range 2 45
jquery + C#.net radiobuttonlist 3 30
abstract class C# 1 31
itextsharp with c# 3 5
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question